Heim > Fragen und Antworten > Hauptteil
代码如下,ENUM已经定义在Account.h文件里面了
typedef NS_ENUM(NSUInteger, httpMethod){
GET = 0,
POST,
PUT,
DELETE
};
//方法定义
-(void) location:(httpMethod)httpMethod withLocation:(NSString *)location;
//在别的类里,调用方法,我想这么做,但是不知道正确的语法
[self.myAccount Account.httpMethod.PUT location: withLocation:location];
天蓬老师2017-05-02 09:25:03
你这么定义只能
[self.myAccount location:GET withLocation:location];
推荐把enum定义成如下:
typedef NS_ENUM(NSUInteger, HttpMethod) {
HttpMethodGet,
HttpMethodPost,
HttpMethodPut,
HttpMethodDelete,
}
[self.myAccount location:HttpMethodGet withLocation:location];
swift是可以做到你的要求的。
enum HttpMethod {
case GET
case POST
}
func a(m : HttpMethod, b : String) {
// ...
}
a(.GET, "hello world")