1

I want to implement a switchs/case where I can use a string to evaluate the switch case.

switch (tmp) {            
    case one: 
        NSLog(@"the string value of tmp is one");
        break;

any of you knows how can I implement something like this?

I really appreciate your help

HelenaM
  • 1,807
  • 6
  • 30
  • 41

1 Answers1

0

You can not use string in switch case statement, you can use only int or char data type. But as i think your question is to make switch case more easy to understandable or readable. So you can make enum for that, like:

typedef enum {
    zero,//by default the value starts from zero. 
    one,
    two
} NumCount;

At the point you have use it.

NumCount tmp = one;

switch (tmp) {            
    case one: 
        NSLog(@"the string value of tmp is one");
        break;
}

I think you understand what i want to say. If you have any doubt please ask from me.

Prateek Prem
  • 1,544
  • 11
  • 14