Created
April 7, 2018 11:16
-
-
Save 3257/9555a8c6201c096457a6a6e59fe4370e 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
import Foundation | |
import FirebaseDatabase | |
struct Unicorn { | |
let imagePath: String | |
let addedBy: String | |
let seenAt: String | |
// Standard init | |
init(imagePath: String, addedBy: String, seenAt: String) { | |
self.imagePath = imagePath | |
self.addedBy = addedBy | |
self.seenAt = seenAt | |
} | |
// Init for reading from Database snapshot | |
init(snapshot: DataSnapshot) { | |
let snapshotValue = snapshot.value as! [String: AnyObject] | |
imagePath = snapshotValue["imagePath"] as! String | |
addedBy = snapshotValue["addedBy"] as! String | |
seenAt = snapshotValue["seenAt"] as! String | |
} | |
// Func converting model for easier writing to database | |
func toAnyObject() -> Any { | |
return [ | |
"imagePath": imagePath, | |
"addedBy": addedBy, | |
"seenAt": seenAt | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment