Objective-C将enum作为参数传递给其他类?

时间:2016-04-13 08:18:22

标签: objective-c enums

这是一个简单的问题,但我在谷歌和stackoverflow上搜索,但我找不到一个例子。

我在Account.h中编写枚举并定义一个方法,将此枚举用作参数:

typedef NS_ENUM(NSUInteger, httpMethod){
    GET = 0,
    POST,
    PUT,
    DELETE
};

//method definition
-(void) location:(httpMethod)httpMethod withLocation:(NSString *)location;

在其他类实现中,我称之为

// I do not know how to pass the enum as parameter
[self.myAccount location:Account.httpMethod.PUT withLocation:string];

1 个答案:

答案 0 :(得分:1)

您只需使用枚举值:

[self.myAccount location:PUT withLocation:string];