【发布时间】:2016-09-07 22:58:48
【问题描述】:
升级到 Xcode 8 (Swift 3) 后,当我尝试在快照中单步执行子记录时,我的 Firebase 查询出现错误 NSFastEnumerationIterator.Element (aka Any) does not conform to protocol 'AnyObject':
for child in snapshot.children {
if (child as AnyObject).value!["postedBy"] != nil {
Xcode 将 child.value["postedBy"] 更改为 (child as AnyObject).value!["postedBy"],这会引发错误。然后我尝试将其更改为
((child as AnyObject).value as? NSDictionary)["postedBy"] != nil
但随后会引发不同的错误Binary operator != cannot be applied to operands of type _ and _
我的方向正确吗?任何帮助将不胜感激。
谢谢!!
最终解决方案:
for child in snapshot.children{
if let postedBy = (snapshot.value as? NSDictionary)?["postedBy"] as? String {
【问题讨论】:
标签: swift firebase firebase-realtime-database swift3 xcode8