Get value from AnyObject Response Swift
1 answer
AnyObject
can be omitted in other class types, so many possibilities!
//if you're confident that responseObject will definitely be of this dictionary type
let name = (responseObject as! [String : AnyObject])["name"]
//optional dictionary type
let name = (responseObject as? [String : AnyObject])?["name"]
//or unwrapping, name will be inferred as AnyObject
if let myDictionary = responseObject as? [String : AnyObject] {
let name = myDictionary["name"]
}
//or unwrapping, name will be inferred as String
if let myDictionary = responseObject as? [String : String] {
let name = myDictionary["name"]
}
Check the link . There's even a section onAnyObject
+13
source to share