swift - 如何在 Firebase 实时数据库中嵌套数据 (Swift)

标签 swift firebase firebase-realtime-database

我在 Firebase 中的数据库目前看起来像这样:

locations: {
    person: ""
    location: ""
}

如何嵌套数据,使其看起来像这样:

locations: {
    person: "" {
        location: ""
}
}

一种结构,其中 locations 是父级,person 是子级,location 是 person 的子级。

我知道这些关系,我只是不太确定语法。

这是我目前使用 Swift 编写的代码:

let locRef = locationRef.childByAutoId()
let locItem = [
    "location": getLocation(),
    "person": senderId
]

locRef.setValue(locItem)

谢谢。

最佳答案

let locRef = locationRef.childByAutoId()
let locItem = [
    senderId : [
        "location": getLocationID()
    ]
]

SenderID 将是这个人的关键,所以你可以通过它的 ID 找到这个人......并且这个 ID 包含一个嵌套的位置键

您只需要逻辑吗?或者您需要工作代码示例吗?

关于swift - 如何在 Firebase 实时数据库中嵌套数据 (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38037749/

相关文章:

java - Firebase简单聊天客户端无法检索值

ios - 我该怎么做才能使设备不会使用蓝牙自动相互连接

ios - 我触摸 iAd,Xcode 识别出我也触摸了背景

swift - 计算属性内的 NSNumberFormatter

ios - 使用带有搜索栏的键搜索 Firebase 数据库

firebase - 如何在flutter中实现onAuthStateChanged()?

java - 如何从 Cloud Firestore 的数组数据字段中获取数据?

ios - 删除节点 Firebase 下的所有项目

ios - 带有 > now() 的 NSFetchedResultsController 不会快速刷新过期的条目

swift - Firebase 在 swift 中创建具有可选值的模型