Swift 3: Enter "Any?" has no subscribers

I keep getting this error for my graph requests

Enter "Any?". has no subscribers

the error indicates the result .... this only happened when I converted to fast 3 ... any ????

let nextrequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me/friends", parameters: ["fields": "name, id, gender"], httpMethod: "GET") nextrequest.start { (connection, result, error) -> Void in guard let listOfFriends = result["data"] as? [AnyObject] else { return } } } 
+6
source share
2 answers

try it

 let nextrequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath:"me/friends", parameters: ["fields": "name, id, gender"], httpMethod: "GET") nextrequest.start { (connection, result, error) -> Void in guard let result = result as? [String:[AnyObject]], let listOfFriends = result["data"] else { return } } } 
+8
source

Little explanation

In Swift 3, the value type is NSDictionary, NSArray, etc. has been changed to Any. Thus, the result of the substring result [key] is Any?, Which cannot be automatically converted to AnyObject.

Before using the result, you must explicitly enter the type [String:[AnyObject]] .

Try using

 let tResult = result as? [String:[AnyObject]] guard let listOfFriends = tResult["data"] else { return; } 

as pointed out by @xhmar's answer

+6
source

All Articles