Swift错误无法转换类型'(AFHTTPRequestOperation ?, AnyObject?)->的值. ()
问题描述:
更新xcode版本8.0(8A218a)迅速3后,出现此错误
After I update xcode Version 8.0 (8A218a) swift 3, I got this error
不能将类型'((AFHTTPRequestOperation ?, AnyObject?)->()'的值转换为预期的参数类型'(((AFHTTPRequestOperation ?, Any?)-> Void)!'
Cannot convert value of type '(AFHTTPRequestOperation?, AnyObject?) -> ()' to expected argument type '((AFHTTPRequestOperation?, Any?) -> Void)!'
这是上面显示错误的以下代码.
This is the following code that's shown error above.
jsonmanager.post( "http://myapi.com",
parameters: nil,
success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in
if(responseObject.object(forKey: "meta")?.object(forKey: "status")?.intValue == 200){....
我做错什么了吗?
在早期版本7.3.1 swift 2中运行良好.
It works well in previous version 7.3.1 swift 2.
答
回调方法签名已更改.在Swift 2中是
The callback method signature has changed. In Swift 2 it was
(AFHTTPRequestOperation?, AnyObject?) -> Void
在Swift 3中是
(AFHTTPRequestOperation?, Any?) -> Void
您应该更改下面的行
success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!)
收件人
success: { (operation: AFHTTPRequestOperation?, responseObject: Any?)