Swift error Cannot convert value of type '(AFHTTPRequestOperation?, AnyObject?) -> ()

廉价感情. 提交于 2019-12-24 05:52:33

问题


After I update xcode Version 8.0 (8A218a) swift 3, I got this error

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){....

Am i doing something wrong ?

It works well in previous version 7.3.1 swift 2.


回答1:


The callback method signature has changed. In Swift 2 it was

(AFHTTPRequestOperation?, AnyObject?) -> Void

In Swift 3 it's

(AFHTTPRequestOperation?, Any?) -> Void

You should change the line below

success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!)

To

success: { (operation: AFHTTPRequestOperation?, responseObject: Any?)


来源:https://stackoverflow.com/questions/39487373/swift-error-cannot-convert-value-of-type-afhttprequestoperation-anyobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!