输入' NSFastEnumerationIterator.Element' (又名'任何')不符合协议' AnyObject'

时间:2016-10-30 00:37:17

标签: swift swift3

我正在尝试将我的应用更新为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))

我该如何重构这个?

1 个答案:

答案 0 :(得分:1)

鉴于您的代码,我认为detailData的类型为NSFastEnumerationIterator.Element

您正在向NSFastEnumerationIterator.Element投射AnyObject

(detailData as AnyObject)

NSFastEnumerationIterator.Element是结构,因此将AnyObject更改为Any

(detailData as Any)