Ios Firebase查询不支持';从Swift 2自动转换为Swift 3后,无法再工作
我要加载Ios Firebase查询不支持';从Swift 2自动转换为Swift 3后,无法再工作,ios,swift,firebase,firebase-realtime-database,Ios,Swift,Firebase,Firebase Realtime Database,我要加载tableViewData的查询不再有效。下面是我的代码 let imageKeysQuery = ref.child("categories").child("Multimedia").child("Fotos").queryOrdered(byChild: "date") imageKeysQuery.observeSingleEvent(of: .value, with: { (snapshot) in for (item) in (sna
tableViewData
的查询不再有效。下面是我的代码
let imageKeysQuery = ref.child("categories").child("Multimedia").child("Fotos").queryOrdered(byChild: "date")
imageKeysQuery.observeSingleEvent(of: .value, with: {
(snapshot) in
for (item) in (snapshot.children) {
if (item as AnyObject).value!["release"] as! Bool != false {
self.keysForImages.append((item as AnyObject).value!["key"] as! String)
self.datesForImages.append((item as AnyObject).value!["date"] as! String)
} else {
let post = "Freizugeben!"
let childUpdates = ["/categories/Multimedia/AAAAA-Fotos-Not-Released/\((item as AnyObject).value!["key"] as! String)": post]
self.ref.updateChildValues(childUpdates)
}
}
self.downloadImages()
})
我在(项目为AnyObject)的每一行中都会收到一条错误消息。value![“.”]
是。以下是错误消息:
Type NSFastEnumerationIterator.Element (aka 'Any') does not conform to protocol AnyObject.
更新:
找到了一个解决方案:
let newsQuery = (ref.child("categories").child("Aktuelles").child("de")).queryOrdered(byChild: "date")
newsQuery.observeSingleEvent(of: .value, with: { snapshot in
for child in snapshot.children {
let data = (child as! FIRDataSnapshot).value! as! NSDictionary
self.titleTableData.append(data["title"]! as! String)
self.textTableData.append(data["text"]! as! String)
self.postKeys.append(data["key"]! as! String)
self.dateTableData.append(data["date"]! as! String)
}
self.loadimages()
})
重要的是将child转换为作为NSDictionary的FIRDataSnapshot
希望这对别人有帮助