7
4

More than 5 years have passed since last update.

fireBaseでDBを作成してiOSから保存、読み込みを行う方法

Posted at

setupに関してはfirebaseの説明通りに進めばok
日本語+画像付きなのですごくわかりやすいです。
スクリーンショット 2016-07-14 23.18.40.png

セットアップが完了したら、DBようの設定を追加します。

まず、podfileに以下を追加、pod updateを行う

pod 'Firebase/Database'
var databaseRef:FIRDatabaseReference = FIRDatabaseReference()//DB
//DB
databaseRef = FIRDatabase.database().reference()

読み込む

func readFbData() {
        databaseRef.observeEventType(.ChildAdded, withBlock: { snapshot in
            let id = snapshot.value!.objectForKey("id") as? String
            }
        })
    }

保存

func saveFbData() {
     let pokeData = ["id": "001", "no": "1"]
    databaseRef.childByAutoId().setValue(pokeData)

}
7
4
0

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
7
4