Firebase BaaS( Backend as a Service)
import UIKit
class ViewController: UIViewController {
var myRootRef:Firebase = Firebase(url:"https://FirabaseSample.firebaseio.com/Users")
@IBAction func write(sender: AnyObject) {
myRootRef.setValue([["ID": [["email": "ooo@gmail.com"],["name": "aaaaa"]]],["ID": [["email": "000@gmail.com"],["name": "bbbb"]]]])
}
@IBAction func read(sender: AnyObject) {
var datas: [(email:String, name: String)] = []
myRootRef.observeEventType(.Value, withBlock: { snapshot in
if let values = snapshot.value as? [[String: [[String: String]]]] {
for value in values {
if let ids = value["ID"], let email = ids[0]["email"], let name = ids[1]["name"] {
datas.append((email, name))
}
}
}
print(datas[0].email) // ooo@gmail.com
print(datas[0].name) // aaaaa
print(datas[1].email) // 000gmail.com
print(datas[1].name) // bbbb
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}