the best way to implement readable switch case with strings in objective-c?

前端 未结 3 1313
野趣味
野趣味 2021-01-31 20:57

In other dynamic languages like ruby, javascript etc. you can do simply this:

switch(someString) {
    case \"foo\":
       //do something;
       break;
    cas         


        
3条回答
  •  野的像风
    2021-01-31 21:31

    typedef enum {
        foo,
        bar
    } FooBar;
    
    - (void) switchFooBar:(NSString *) param {
        switch([[cases objectForKey:param] intValue]) {
            case foo:
                NSLog(@"its foo");
                break;
            case bar:
                NSLog(@"its bar");
                break;
            default: 
                NSLog(@"its default");
                break;
        }
    }
    

提交回复
热议问题