swift 3: Type 'Any?' has no subscript members

后端 未结 2 1215
青春惊慌失措
青春惊慌失措 2020-11-29 12:36

I keep getting this error for my graph requests??

Type \'Any?\' has no subscript members

the error points at result.... this onl

2条回答
  •  误落风尘
    2020-11-29 13:06

    A little explanation

    In Swift 3, the Value type of NSDictionary, NSArray, etc. have been changed to Any. So the result type of subscript result[key] is Any?, which cannot be automatically converted to AnyObject.

    You have to explicitly cast into [String:[AnyObject]] type before using the result.

    Try using,

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

    as mentioned in the answer of @xhmar

提交回复
热议问题