Skip to content

Instantly share code, notes, and snippets.

@romyilano
Forked from davideast/MyViewController.swift
Last active March 4, 2016 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romyilano/aab8b3760fa9982775a4 to your computer and use it in GitHub Desktop.
Save romyilano/aab8b3760fa9982775a4 to your computer and use it in GitHub Desktop.
import UIKit
class MyViewController: UIViewController {
// Store ref and handle as implicitly unwrapped optionals
// explanation about this > because the initializer might not be called esp from the storyboard
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