我正在尝试将对象ViewingPost
附加到这些对象的数组中。当我执行此处显示的操作时,它会起作用:
for (_,post) in snap {
let posst = ViewingPost()
if let totLikes = post["likes"] as? Int, let pathToImage = post["pathToImage"] as? String, let postID = post["postID"] as? String {
let postNum = "post" + postID
posst.pathToImage = pathToImage
posst.postID = postID
posst.likes = totLikes
self.posts.append(posst)
for key in 1 ... arr.count {
let isEq = arr[key - 1] == postNum
print(isEq)
if isEq {
ref.child(formattedDateD).child(postNum).observeSingleEvent(of: .value, with: { (snapsh) in
let snapshP = snapsh.value as! Int
})
}
}
}
}
尽管当我将其将对象附加到数组的部分移动到我想要的位置时,它仍然无法工作:
for (_,post) in snap {
let posst = ViewingPost()
if let totLikes = post["likes"] as? Int, let pathToImage = post["pathToImage"] as? String, let postID = post["postID"] as? String {
let postNum = "post" + postID
for key in 1 ... arr.count {
let isEq = arr[key - 1] == postNum
print(isEq)
if isEq {
ref.child(formattedDateD).child(postNum).observeSingleEvent(of: .value, with: { (snapsh) in
let snapshP = snapsh.value as! Int
posst.pathToImage = pathToImage
posst.postID = postID
posst.likes = totLikes
self.posts.append(posst)
})
}
}
}
}
有人可以帮忙吗?