I've updated Xcode to version 8 and now there is some problem with Firebase. This is a piece of code:
let target = snapshot.value!["target"] as! NSDictionary
self.myZodiac.text = snapshot.value!["zodiac"] as! String
let nsHeight = snapshot.value!["height"] as! NSNumber
// Type 'Any' has no subscript members
In Swift 2.3 all of this works! how to fix it?
One more:
var messagesDictionary = [[String:Int]]()
userRef.observe(FIRDataEventType.value, with: { (snapshot) in
for item in snapshot.children.allObjects {
for itemDic in self.messagesDictionary {
for (key,value) in itemDic {
if (item as AnyObject).key == key {
var photo = UIImage()
let age = (item as AnyObject).value!["age"] as! NSNumber as Int //error Type 'Any' does not conform to protocol 'AnyObject'
let name = (item as AnyObject).value!["name"] as! String //error Type 'Any' does not conform to protocol 'AnyObject'
if (item as AnyObject).hasChild("avatar"){
let avatar = (item as AnyObject).value!["avatar"] as! String //error Type 'Any' does not conform to protocol 'AnyObject'
self.storageRef.child(key).child(avatar).data(withMaxSize: 5 * 1024 * 1024, completion: { (data, error) -> Void in
if (error != nil) {
} else {
photo = UIImage(data:data!)!
}
})
////
}else{
photo = UIImage(named: "no_avatar")!
}
}
}
}
}
})
first example i used:
let target = (snapshot.value as? NSDictionary)?["target"] as! NSDictionary
self.myZodiac.text = (snapshot.value as? NSDictionary)?["zodiac"] as! String
let nsHeight = (snapshot.value as? NSDictionary)?["height"] as! NSNumber
now what to do with item as AnyObject from second piece of code?