Created
December 11, 2015 23:11
-
-
Save ziyang0621/88f47650cabf8436f145 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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