I want to set a text field to look through a switch statement to find the corresponding case. Can I just do that like this?

switch(textField){
    case 'someCase':
        // do something
        break;
    default:
        // do something else
        break;
}

Considering I already created an outlet for it in the @interface file and have connected a button to this as an action (in the @implementation file).

Recommended Answers

All 2 Replies

No switch takes an integer you need if then else if construct

if ([textfield.text isequaltostring:@"someCase"]) {
    // do something
} else if ([textfield.text isequaltostring:@"anotherCase"]) {
    // do something else
} else {
    // do yet another thing
}

No switch takes an integer you need if then else if construct

Really? I didn't know that. Well, thank you. I guess I better go make those if statements.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.