我正在尝试将一个子级的所有值检索到集合视图中
我不断收到此错误
无法在此行中强制转换类型为"__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()
})
据
我所知,您的快照中有很多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
}
}
}