Last active
August 11, 2017 09:49
-
-
Save phucnm/949e7e4e1a4386233851efc513ff8276 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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