This file contains 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 Data.List | |
fib :: Int -> Int | |
fib 0 = 1 | |
fib 1 = 1 | |
fib n = fib (n - 1) + fib (n - 2) | |
main :: IO () | |
main = putStrLn $ intercalate ", " $ map show $ map fib [0..10] |
This file contains 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 | |
enum ModelError: Error { | |
case invalidProperties | |
} | |
protocol Model { | |
init?(snapshot: FIRDataSnapshot) | |
This file contains 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 Book { | |
var id: String? | |
var isbn: String | |
var title: String | |
var authors: String | |
var year: String | |
var country: String |
This file contains 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", |
This file contains 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 bookRef = db.reference(withPath: Endpoint.book("-KnEUaDbm6-snUq_Ojzo").path) | |
bookRef.observeSingleEvent(of: .value, with: { snapshot in | |
guard let book = Book(snapshot: snapshot) else { return } | |
print(book.title) | |
}) |
This file contains 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 UIKit | |
protocol ReusableView: class { | |
static var defaultReuseIdentifier: String { get } | |
} | |
extension ReusableView where Self: UIView { | |
static var defaultReuseIdentifier: String { | |
return String(describing: self) |
This file contains 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 book = FirestoreBook( | |
isbn: "95-0443-843-0", | |
title: "Do Androids Dream of Electric Sheep?", | |
authors: ["Philip K. Dick"], | |
year: 1968, | |
country: "United States", | |
createdAt: Date(), | |
format: .ebook, | |
award: nil) |
This file contains 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 book = FirestoreBook( | |
documentID: nil, | |
isbn: "95-0443-843-0", | |
title: "Do Androids Dream of Electric Sheep?") | |
let firestore = Firestore.firestore() | |
let ref = firestore.collection("books").document() | |
ref.setModel(book) |
This file contains 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 firestore = Firestore.firestore() | |
let ref = firestore.document("books/95-0443-843-0") | |
ref.getModel(FirestoreBook.self) { book, error in | |
guard let book = book else { return } | |
print("The book \(book.title) was published in \(book.year).") | |
} |
This file contains 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 { | |
let documentID: String! | |
var isbn: String | |
var title: String | |
} | |
extension FirestoreBook: FirestoreModel { | |
init?(modelData: FirestoreModelData) { | |
try? self.init( |
OlderNewer