Swift 3 Value of type "Any?" has no member object '

I updated swift 3 and I found many errors. This is one of them:

A value of type "Any?" doesn't have a member object '

This is my code:

jsonmanager.post( "http://myapi.com",
                      parameters: nil,
                      success: { (operation: AFHTTPRequestOperation?,responseObject: Any?) in
                        if(((responseObject? as AnyObject).object(forKey: "meta") as AnyObject).object(forKey: "status")?.intValue == 200 && responseObject?.object(forKey: "total_data")?.intValue > 0){
                            let aa: Any? = (responseObject? as AnyObject).object(forKey: "response")

                            self.data = (aa as AnyObject).mutableCopy() 
                        }

New error update:

The optional chain has no effect, the expression already produces "Any?"

and

It is not possible to call a value of the non-function type "Any ?!"

Works well in previous version 7.3.1 swift 2.

This is json's answer:

{
 "meta":{"status":200,"msg":"OK"},
        "response":[""],
        "total_data":0
}
+4
source share
2 answers

Swift 2, Swift 3 Objective-C id Any? AnyObject? (. ). , AnyObject. :

jsonmanager.post("http://myapi.com", parameters: nil) { (operation: AFHTTPRequestOperation?, responseObject: Any?) in
    let response = responseObject as AnyObject?
    let meta = response?.object(forKey: "meta") as AnyObject?
    let status = meta?.object(forKey: "status") as AnyObject?
    let totalData = response?.object(forKey: "total_data") as AnyObject?
    if status?.intValue == 200 && totalData?.intValue != 0 {
        let aa = response?.object(forKey: "response") as AnyObject?
        self.data = aa?.mutableCopy() 
    }
}
+17

responseObject Optional ( , Any?), , , , responseObject?.object(forKey: "meta") .. , Optional, Optional, , Objective-C .

0

Source: https://habr.com/ru/post/1654649/


All Articles