NSFastEnumerationIterator.Element(又名 Any)不符合协议 'AnyObject'
NSFastEnumerationIterator.Element (aka Any) does not conform to protocol 'AnyObject'
升级到 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 {
尝试:-
for child in snapshot.children{
if let postedBy = child.value!["postedBy"] as? String { .. }}
升级到 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 {
尝试:-
for child in snapshot.children{
if let postedBy = child.value!["postedBy"] as? String { .. }}