gpt4 book ai didi

ios - 如何在 Swift 中将 Firebase 数据库快照转换为数组列表?

转载 作者:行者123 更新时间:2023-11-30 11:15:14 25 4
gpt4 key购买 nike

我正在使用 Swift 和 Firebase 制作一个应用。我想获取一个数组列表,其中包含某个用户 ID 下的所有数字(下面附有图像)。我的意思是我希望能够调用一个函数,该函数返回一个数组列表,其中包含作为用户 ID 的子级放置的每个整数(从低到高),但不包含它们的值(在本例中为“true”) )。我已经获得了数据快照(请参阅下面的代码),但我不确定现在该怎么做。

我的代码:

func likeToLikeForAll() {

let uid = Auth.auth().currentUser?.uid
Database.database().reference().child("Liked Movies").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
print()
print("SNAP:")
print(snapshot.value!)
print()
}
})
}

该函数打印: enter image description here

这是实时数据库的图像: enter image description here

最佳答案

根据键创建数组

let array = Array(dictionary.keys)

关于ios - 如何在 Swift 中将 Firebase 数据库快照转换为数组列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51811010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com