LoginSignup
1

More than 5 years have passed since last update.

Firebase Cloud FirestoreをSwiftで使う時のデータ型一覧

Posted at

概要

Firebaseのデータベースの一つ、CloudFirestoreを利用した時に利用できるデータ型を一覧にしました。

一覧

Left align Right align
ブール型 Bool
文字列 String
整数 Int
浮動小数点 Float
日付 NSDate
配列 Array
辞書型 Dictionary
Null値 nil

データ例 in Swift

let docData: [String: Any] = [
    "stringExample": "Hello world!", //String
    "booleanExample": true, // Bool
    "numberExample": 3.14159265, // Float
    "dateExample": NSDate(), //日付
    "arrayExample": [5, true, "hello"], //Array
    "nullExample": NSNull(), // nil
    "objectExample": [ 
        "a": 5,
        "b": [
            "nested": "foo"
        ]
    ] //dictionary
]

db.collection("data").document("one").setData(docData) { err in
    if let err = err {
        print("Error writing document: \(err)")
    } else {
        print("Document successfully written!")
    }
}

型が混同したフィールドがあるときの決定論的順序付け

  1. Null値 -> nil
  2. ブール型 -> bool
  3. 数値順に並べられた整数値と浮動少数点値 -> Int, Float
  4. 日付の値 -> NSDate
  5. テキスト文字列の値 -> String
  6. バイト値
  7. Cloud Firestoreの参照 -> String
  8. 地理的座標値
  9. 配列値
  10. マップ値

参考文献

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1