gpt4 book ai didi

swift - 某些数据未从 Firebase 数据库 Swift 3 中读取

转载 作者:行者123 更新时间:2023-11-28 12:16:45 24 4
gpt4 key购买 nike

我在 firebase 中有一个数据库,看起来像这样 enter image description here
我正在尝试获取给定 key 的网址。但是,我只能获得其中几个键的 url,其余的返回 nil?我没有看到关于为什么有些键会返回我正在寻找的值而有些则不会的模式?这是我正在使用的代码

static func getProfilePictureURL(imageID key: String, completionHandler: @escaping (_ return: String?, _ error: String?) -> Void){
databaseReference.child("userSelfies").child(userIDGlobal).observeSingleEvent(of: .value, with: { (snapshot) in
// Get user value

let value = snapshot.value as? [String: Any]
print(value!["150575773394828"])

if let url = value?[key] {
print("url",url)
//completionHandler(url, nil)
}

}) { (error) in
print(error.localizedDescription)
completionHandler(nil, error.localizedDescription)

}
}

我已经尝试了所有方法,是的,页面已重新加载,所以数据肯定在那里。

最佳答案

所以看起来函数 getProfilePictureURL 只需要获取一个 imageID key 的图像,是吗?如果您只查询要查找的键会怎样?

static func getProfilePictureURL(imageID key: String, completionHandler: @escaping (_ return: String?, _ error: String?) -> Void){
databaseReference.child("userSelfies/\(userIDGlobal)/\(key)).observeSingleEvent(of: .value, with: { (snapshot) in
// Get user value

let url = snapshot.value as? String
print("url",url)
//completionHandler(url, nil)

}) { (error) in
print(error.localizedDescription)
completionHandler(nil, error.localizedDescription)

}
}

关于swift - 某些数据未从 Firebase 数据库 Swift 3 中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46288405/

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