Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Firebase references in a UIViewController
import UIKit
class MyViewController: UIViewController {
// Store ref and handle as implicitly unwrapped optionals
var ref: Firebase!
var handle: UInt!
override func viewDidLoad() {
super.viewDidLoad()
// Initialize Reference
ref = Firebase(url: "https://<YOUR-FIREBASE-APP>.firebaseio.com/")
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// Create listener and store handle
handle = ref.observeEventType(.Value) { print($0) }
}
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
// Remove listener with handle
ref.removeObserverWithHandle(handle)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment