Last active
June 23, 2017 23:24
-
-
Save ts95/faba84eb424deef3cd96d0f6e1776acf to your computer and use it in GitHub Desktop.
Example of storing a new book model instance in the Firebase database
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
let db = FIRDatabase.database() | |
let booksRef = db.reference(withPath: Endpoint.books.path) | |
var newBook = Book( | |
id: nil, | |
isbn: "95-0443-843-0", | |
title: "Do Androids Dream of Electric Sheep?", | |
authors: "Philip K. Dick", | |
year: "1968", | |
country: "United States", | |
createdAt: Date() | |
) | |
do { | |
try newBook.store(at: booksRef) | |
} catch ModelError.invalidProperties { | |
print("At least one of the properties has an invalid value.") | |
} catch { | |
print("Someting else went wrong.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment