Skip to content

Instantly share code, notes, and snippets.

@ts95
Last active June 23, 2017 23:24
Show Gist options
  • Save ts95/faba84eb424deef3cd96d0f6e1776acf to your computer and use it in GitHub Desktop.
Save ts95/faba84eb424deef3cd96d0f6e1776acf to your computer and use it in GitHub Desktop.
Example of storing a new book model instance in the Firebase database
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