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/949e7e4e1a4386233851efc513ff8276 to your computer and use it in GitHub Desktop.

Select an option

Save phucnm/949e7e4e1a4386233851efc513ff8276 to your computer and use it in GitHub Desktop.
extension BaseMappable {
static var firebaseIdKey : String {
get {
return "FirebaseIdKey"
}
}
init?(snapshot: DataSnapshot) {
guard var json = snapshot.value as? [String: Any] else {
return nil
}
json[Self.firebaseIdKey] = snapshot.key as Any
self.init(JSON: json)
}
}
class Post: Mappable {
var postId: String?
var title: String?
var content: String?
var author: String?
func mapping(map: Map) {
postId <- map[Post.firebaseIdKey]
title <- map["title"]
content <- map["content"]
author <- map["author"]
}
required init?(map: Map) { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment