升级到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 {
答案 0 :(得分:1)
尝试: -
for child in snapshot.children{
if let postedBy = child.value!["postedBy"] as? String { .. }}