File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,36 @@ struct Model: Codable {
2121}
2222```
2323
24+ ### Firebase Database usage
25+
26+ This is how you would use the library with [ Firebase Realtime Database] ( https://firebase.google.com/products/realtime-database/ ) :
27+
28+ ``` swift
29+ import Firebase
30+ import CodableFirebase
31+
32+ let model: Model // here you will create an instance of Model
33+ let data = try ! FirebaseEncoder ().encode (model)
34+
35+ Database.database ().reference ().child (" model" ).setValue (data)
36+ ```
37+
38+ And here is how you would read the same value from [ Firebase Realtime Database] ( https://firebase.google.com/products/realtime-database/ ) :
39+
40+ ``` swift
41+ Database.database ().reference ().child (" model" ).observeSingleEvent (of : .value , with : { (snapshot) in
42+ guard let value = snapshot.value else { return }
43+ do {
44+ let model = try FirebaseDecoder ().decode (Model.self , from : value)
45+ print (model)
46+ } catch let error {
47+ print (error)
48+ }
49+ })
50+ ```
51+
52+ ### Firestore usage
53+
2454And this is how you would encode it with [ Firebase Firestore] ( https://firebase.google.com/products/firestore/ ) :
2555
2656``` swift
You can’t perform that action at this time.
0 commit comments