File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 11# CodableFirebase
2- Use Codable with Firebase
2+ Use [ Codable] ( https://developer.apple.com/documentation/swift/codable ) with [ Firebase] ( https://firebase.google.com )
33
44[ ![ Carthage compatible] ( https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat )] ( https://github.com/Carthage/Carthage )
55[ ![ 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
3737 }
3838}
3939```
40+
41+ And this is how you would decode the same model with [ Firebase Firestore] ( https://firebase.google.com/products/firestore/ ) :
42+
43+ ``` swift
44+ Firestore.firestore ().collection (" data" ).document (" one" ).getDocument { (document, error) in
45+ if let document = document {
46+ let model = try ! FirestoreDecoder ().decode (Model.self , from : document.data ())
47+ print (" Model: \( model ) " )
48+ } else {
49+ print (" Document does not exist" )
50+ }
51+ }
52+ ```
You can’t perform that action at this time.
0 commit comments