Skip to content

Instantly share code, notes, and snippets.

@phucnm
Last active August 11, 2017 09:49
Show Gist options
  • Select an option

  • Save phucnm/84fe9b9f9663c74f74416b90dbc88904 to your computer and use it in GitHub Desktop.

Select an option

Save phucnm/84fe9b9f9663c74f74416b90dbc88904 to your computer and use it in GitHub Desktop.
func getPosts() -> Observable<[Post]> {
let postRef = Database.database().reference()
.child("posts")
return postRef.rx_observeSingleEvent(of: .value)
.map { Mapper<Post>().mapArray(snapshot: $0) }
}
getPosts().subscribe(onNext: { posts in
//show the data or do whatever you want
}, onError: { error in
//show an alert
}).disposed(by: disposeBag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment