我正在尝试将我的应用更新为Swift 3.0并且已经出现错误:Type 'NSFastEnumerationIterator.Element' (aka 'Any') does not conform to protocol 'AnyObject'
在线:
self.friends.append(Friend(userName: (detailData as AnyObject).value["userName"] as! String, phoneNumber: detailData.value["phoneNumber"] as! String, status: "Friend", statusSort: 2, name: detailData.value["userName"] as! String, userID: detailData.key))
我该如何重构这个?
答案 0 :(得分:1)
鉴于您的代码,我认为detailData
的类型为NSFastEnumerationIterator.Element
:
您正在向NSFastEnumerationIterator.Element
投射AnyObject
:
(detailData as AnyObject)
但NSFastEnumerationIterator.Element
是结构,因此将AnyObject
更改为Any
:
(detailData as Any)