1

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.

stevengbu
  • 243
  • 1
  • 3
  • 13

1 Answers1

5

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?)
donnywals
  • 7,241
  • 1
  • 19
  • 27
  • After i changed i got this message : Cannot call value of non-function type 'Any?!' – stevengbu Sep 15 '16 at 01:23
  • And this inside if : Value of type 'Any?' has no member 'object' – stevengbu Sep 15 '16 at 01:26
  • 1
    You could try to cast the `responseObject` to `AnyObject`. `AnyObject` and `Any` are pretty different so you're going to have to rewrite that par of your app to properly handle `Any` instead of `AnyObject` – donnywals Sep 15 '16 at 09:00