gpt4 book ai didi

ios - 在 Swift 3.0 中访问嵌套的 NSDictionary 值

转载 作者:搜寻专家 更新时间:2023-11-01 06:37:14 26 4
gpt4 key购买 nike

我有从 Firebase 收到的以下数据。我已将 snapshotValue 设为 NSDictionary。

enter image description here

self.ref.child("users").child(facebookID_Firebase as! String).observeSingleEvent(of: .value, with: { (snapshot) in
let snapshotValue = snapshot.value as? NSDictionary
print(snapshotValue, "snapshotValue")
//this line of code doesn't work
//self.pictureURL = snapshot["picture"]["data"]["url"]
}) { (error) in
print(error.localizedDescription)
}

我试过了 How do I manipulate nested dictionaries in Swift, e.g. JSON data? , How to access deeply nested dictionaries in Swift ,和其他解决方案还没有运气。

如何访问数据 key 和图片 key 中的 url 值?

我可以在 Firebase 中进行另一个引用并获取值,但我正在尝试保存另一个请求。 😓

最佳答案

当您在 swift 中引用字典的键时,您会得到一个未包装的值。这意味着它可以为零。您可以强制解包该值,也可以使用漂亮的 if let =

这应该可行。

if let pictureUrl = snapshot["picture"]["data"]["url"] {
self.pictureURL = pictureUrl
}

关于ios - 在 Swift 3.0 中访问嵌套的 NSDictionary 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40120042/

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