Swift error Cannot convert value of type '(AFH

2019-08-01 18:57发布

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条回答
Fickle 薄情
2楼-- · 2019-08-01 19:39

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?)
查看更多
登录 后发表回答