Switch语句不处理NS_ENUM值

pbu*_*eit 1 enums objective-c switch-statement

我有一个在Objective-c标头中定义的枚举,如下所示:

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

};
@end
Run Code Online (Sandbox Code Playgroud)

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

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

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

    }

}
Run Code Online (Sandbox Code Playgroud)

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

在切换中未处理枚举值'PROSPECT'和'CUSTOMER'

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

Jef*_*mas 5

你忘记了关键字case.

switch(accountType)
{
    case CUSTOMER:
    {
        [self performSegueWithIdentifier:@"customerDetails" sender:accountId];
        break;
    }

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

}
Run Code Online (Sandbox Code Playgroud)

注意:您发布的代码创建了两个标签.