我正在尝试将一个孩子的所有值检索到collectionView
我一直收到此错误
无法在此行中投射“__NSDictionaryM”类型的值
let follower = snapshotValue!["Followers"] as! String
这是我的代码
followRef.child("users").child((FIRAuth.auth()?.currentUser?.displayName)!).observe(FIRDataEventType.value, with: {
snapshot in
let snapshotValue = snapshot.value as? Dictionary<String,AnyObject>
let follower = snapshotValue!["Followers"] as! String
self.postsFollow.insert(postFollowStruct(follower: follower) , at: 0)
self.followersView.reloadData()
})
答案 0 :(得分:0)
根据我的理解,你的snapshot.value中有很多json对象?那么你想要将每个对象转换为一个对象并将它们放入一个数组中吗?
if let dict = snapshot.value as? [String: AnyObject]{
let followers = dict
for follower in followers {
if let restDict = follower.value as? [String:AnyObject] {
let followerObj = Follower()
followerObj.setValuesForKeys(restDict)
//add to array
}
}
}