如何解决此错误:
func loginMobilephone(phone : String , password : String , withBlock block : ((result:NSDictionary , error: NSError)-> Void)!)
{
var params : AnyObject! = ["username" :phone,"passwd": password, "session_id" : Constant.instance().session]
var path : String! = "/account/common/login";
NetworkManager.sharedClient().postPath(path, parameters: params, withBlock: block)
NetworkManager.sharedClient().postPath(<#path: String!#>, parameters: <#[NSObject : AnyObject]!#>, withBlock: <#(([NSObject : AnyObject]!, NSError!) -> Void)!##([NSObject : AnyObject]!, NSError!) -> Void#>)
}
错误是:
无法使用类型'的参数列表调用'postPath'(String!, 参数:AnyObject!,withBlock :((结果:NSDictionary,错误: NSError) - &gt;空隙)!)'
或如何将其转换为Swift:
+(void)loginMobilephone:(NSString *)phone password:(NSString *)password withBlock:(void (^)(NSDictionary *, NSError *))block{
NSDictionary *params = @{@"username" : phone,
@"passwd" : password,
@"session_id":[[Constant instance] session]
};
[[NetworkManager sharedClient] postPath:APIUSERLOGIN parameters:params withBlock:block]; }
答案 0 :(得分:0)
params应该是字典[NSObject:AnyObject]而不是AnyObject!。
试试这样:
let params: [NSObject : AnyObject] = ["username" : phone, "passwd" : password, "session_id" : Constant.instance().session]
并将方法参数更改为此
func loginMobilephone(phone: String, password: String, withBlock block: ((result: [NSObject : AnyObject] , error: NSError)-> Void) ) {
// ... code
}