Skip to content

Commit 969cd78

Browse files
author
Oleksii Dykan
authored
Update README.md
1 parent 3da0721 commit 969cd78

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
2454
And this is how you would encode it with [Firebase Firestore](https://firebase.google.com/products/firestore/):
2555

2656
```swift

0 commit comments

Comments
 (0)