From 0d13034c79d61b71f38fbb63f0147761dab5a7fa Mon Sep 17 00:00:00 2001 From: Oleksii Dykan Date: Tue, 24 Oct 2017 14:59:58 +0200 Subject: [PATCH] Update README.md --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 36f9dab..dbde039 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # CodableFirebase -Use Codable with Firebase +Use [Codable](https://developer.apple.com/documentation/swift/codable) with [Firebase](https://firebase.google.com) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![Build Status](https://travis-ci.org/alickbass/CodableFirebase.svg?branch=master)](https://travis-ci.org/alickbass/CodableFirebase) @@ -37,3 +37,16 @@ Firestore.firestore().collection("data").document("one").setData(docData) { err } } ``` + +And this is how you would decode the same model with [Firebase Firestore](https://firebase.google.com/products/firestore/): + +```swift +Firestore.firestore().collection("data").document("one").getDocument { (document, error) in + if let document = document { + let model = try! FirestoreDecoder().decode(Model.self, from: document.data()) + print("Model: \(model)") + } else { + print("Document does not exist") + } +} +```