ios - 是否可以将坐标数组保存到 firebase?

标签 ios arrays swift firebase

我有一组经纬度坐标,我想将其保存到 firebase。我知道有 a normal我可以使用的方式。但我想知道如何保存整个阵列。

我想保存的数组如下所示:

(1.323, 2.334),(6.323, 7.334),(0.323, 65.334),(43.323, 32.334)...

我正在使用实时数据库。

最佳答案

let databaseRef = Database.database().reference()
let coordinatesRef = databaseRef.child("path/to/coordinates")

func save(coordinates: [(Double, Double)], completion: @escaping (Error?) -> ()) {
    coordinatesRef.setValue(coordinates.map { [$0, $1] }) { completion($0) }
}

save(coordinates: [
    (1.323, 2.334),
    (6.323, 7.334),
    (0.323, 65.334),
    (43.323, 32.334)
]) { error in
    if let error = error {
        print("❌ Saving coordinates to Firebase failed", error)
    } else {
        print("🔥 Saving coordinates to Firebase succeeded")
    }
}

关于ios - 是否可以将坐标数组保存到 firebase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54609201/

相关文章:

ios - 解决 Xcode 中的内存泄漏

ios - Xcode Storyboard : Internal error. 请提交错误

PHP 和 MySQL - 哪种变量类型最适合该数组?

java - Android Java ArrayList 尽可能大的尺寸

ios - Swift 计算属性返回值

ios - 将字典追加到 Swift 数组

ios - 在 iOS 上为文件 ://URLs causes "Frame load interrupted" error 使用自定义 NSURLProtocol

ios - 无法从 Paypal SDK 获取访问 token 。遇到异常说 “Authentication needed”

javascript - 如何在 Type Script/Java Script 中将字符串数组值合并到对象数组中的特定属性

ios - 有什么方法可以持久化 Swift 闭包吗?