Switch 语句未处理 NS_ENUM 个值
Switch Statement Not Handling NS_ENUM values
我在 objective-c header 中定义了一个枚举,如下所示:
#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;
}
}
}
如您所见,枚举的两个选项在开关中都有相应的路径。然而出于某种原因,我收到一条编译器警告说
Enumeration values 'PROSPECT' and 'CUSTOMER' not handled in
switch
为了确定,我在该方法中放置了一些断点。正如警告所指示的那样,它虽然没有击中箱子就掉了下来。我还尝试重命名枚举值,以确保它们在某处没有冲突并且仍然没有。我在这里完全被难住了。任何帮助将不胜感激。
您忘记了关键字 case
。
switch(accountType)
{
case CUSTOMER:
{
[self performSegueWithIdentifier:@"customerDetails" sender:accountId];
break;
}
case PROSPECT:
{
[self performSegueWithIdentifier:@"prospectDetails" sender:accountId];
break;
}
}
注意:您发布的代码创建了两个 labels。
我在 objective-c header 中定义了一个枚举,如下所示:
#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;
}
}
}
如您所见,枚举的两个选项在开关中都有相应的路径。然而出于某种原因,我收到一条编译器警告说
Enumeration values 'PROSPECT' and 'CUSTOMER' not handled in switch
为了确定,我在该方法中放置了一些断点。正如警告所指示的那样,它虽然没有击中箱子就掉了下来。我还尝试重命名枚举值,以确保它们在某处没有冲突并且仍然没有。我在这里完全被难住了。任何帮助将不胜感激。
您忘记了关键字 case
。
switch(accountType)
{
case CUSTOMER:
{
[self performSegueWithIdentifier:@"customerDetails" sender:accountId];
break;
}
case PROSPECT:
{
[self performSegueWithIdentifier:@"prospectDetails" sender:accountId];
break;
}
}
注意:您发布的代码创建了两个 labels。