Skip to content

Instantly share code, notes, and snippets.

@3257
Created April 7, 2018 11:16
Show Gist options
  • Save 3257/9555a8c6201c096457a6a6e59fe4370e to your computer and use it in GitHub Desktop.
Save 3257/9555a8c6201c096457a6a6e59fe4370e to your computer and use it in GitHub Desktop.
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