Skip to content

Instantly share code, notes, and snippets.

@ziyang0621
Created December 11, 2015 23:11
Show Gist options
  • Save ziyang0621/88f47650cabf8436f145 to your computer and use it in GitHub Desktop.
Save ziyang0621/88f47650cabf8436f145 to your computer and use it in GitHub Desktop.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let ref = Firebase(url: "<YOUR_FIREBASE_NAMESPACE>.firebaseio.com/")
ref.observeEventType(.ChildAdded, withBlock: {
(snapshot) -> Void in
print("the value: \(snapshot.value)")
}){
(error) -> Void in
print("there is an error: \(error.description)")
}
}
@IBAction func test(sender: AnyObject) {
let ref = Firebase(url: "<YOUR_FIREBASE_NAMESPACE>.firebaseio.com/")
let childRef = ref.childByAutoId()
childRef.setValue(textField.text, withCompletionBlock: {
(error:NSError?, ref:Firebase!) in
if (error != nil) {
print("Data could not be saved.")
} else {
print("Data saved successfully!")
}
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment