程式碼如下,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")