Last active
November 10, 2017 15:40
-
-
Save ts95/6dd85fa7ea0668c5b63a795f99fb2f3e 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
struct FirestoreBook { | |
var isbn: String | |
var title: String | |
var authors: [String] | |
var year: Int | |
var country: String | |
var createdAt: Date | |
var format: Format | |
var award: String? | |
enum Format: String, StringRawRepresentable { | |
case paperback | |
case pocket | |
case ebook | |
} | |
} | |
extension FirestoreBook: FirestoreModel { | |
var documentID: String! { | |
return isbn | |
} | |
var customID: String? { | |
return "isbn" | |
} | |
init?(modelData: FirestoreModelData) { | |
try? self.init( | |
isbn: modelData.documentID, | |
title: modelData.value(forKey: "title"), | |
authors: modelData.value(forKey: "authors"), | |
year: modelData.value(forKey: "year"), | |
country: modelData.value(forKey: "country"), | |
createdAt: modelData.value(forKey: "createdAt"), | |
format: modelData.value(forKey: "format"), | |
award: modelData.optionalValue(forKey: "award") | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment