Switch语句不处理NS_ENUM值

时间:2015-05-20 17:29:55

标签: objective-c enums switch-statement

我在一个Objective-c标题中定义了一个枚举,如下所示:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface CustomerAndProspectMapViewController : UIViewController<MKMapViewDelegate>
typedef NS_ENUM(NSInteger, TypeEnum)
{
    PROSPECT,
    CUSTOMER

};
@end

然后在实现中我有一个函数,它将TypeEnum作为参数并使用开关来运行一些条件代码:

-(void) handleTestNavigation:(NSString *)accountId :(TypeEnum)accountType
{
    switch(accountType)
    {
        CUSTOMER:
        {
            [self performSegueWithIdentifier:@"customerDetails" sender:accountId];
            break;
        }

        PROSPECT:
        {
            [self performSegueWithIdentifier:@"prospectDetails" sender:accountId];
            break;
        }

    }

}

如您所见,枚举的两个选项在交换机中都有相应的路径。但出于某种原因,我收到编译器警告说

  

未处理枚举值'PROSPECT'和'CUSTOMER'   开关

为了确保,我在该方法中加入了一些断点。正如警告所示,虽然没有遇到过案件但它已经下降了。我也尝试重命名枚举值,以确保它们在某处并没有任何冲突。我完全被这里难住了。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:5)

您忘记了关键字pref_num = re.compile(r'[type1|type2]-\d+')

case

注意:您发布的代码创建了两个labels