Add a note in the Changelog about Observables

This commit is contained in:
Pedro Piñera Buendía 2016-05-07 22:31:41 +02:00
parent d4f07c8749
commit f98f45af74
2 changed files with 33 additions and 0 deletions

View File

@ -1,3 +1,7 @@
### Version 2.2.6
- Add Observable feature https://github.com/pepibumur/SugarRecord/pull/243
- Fix a CoreDataStorage `journal_mode` property not set properly.
### Version 2.2.5 ### Version 2.2.5
- Updated Carthage Quick/Nimble dependencies - Updated Carthage Quick/Nimble dependencies

View File

@ -216,6 +216,35 @@ func rx_fetch<T>(request: Request<T>) -> Observable<[T]>
<br> <br>
> This is the first approach of SugarRecord for the interface. We'll improve it with the feedback you can report and according to the use of the framework. Do not hesitate to reach us with your proposals. Everything that has to be with making the use of CoreData/Realm easier, funnier, and enjoyable is welcome! :tada: > This is the first approach of SugarRecord for the interface. We'll improve it with the feedback you can report and according to the use of the framework. Do not hesitate to reach us with your proposals. Everything that has to be with making the use of CoreData/Realm easier, funnier, and enjoyable is welcome! :tada:
### Observable
SugarRecord provides a component, `Observable` that allows observing changes in the DataBase. It uses Realm notifications and CoreData `NSFetchedResultsController` under the hood.
**Observing**
```swift
class Presenter {
var observable: Observable<Track>!
func setup() {
let request: Request<Track> = Request<Track>().filteredWith("artist", equalTo: "pedro")
self.observable = storage.instance.observe(request)
self.observable.observe { changes in
case .Initial(let objects):
print("\(objects.count) objects in the database")
case .Update(let deletions, let insertions, let modifications):
print("\(deletions.count) deleted | \(insertions.count) inserted | \(modifications.count) modified")
case .Error(let error):
print("Something went wrong")
}
}
}
```
> **Retain**: Observable must be retained during the observation lifecycle. When the `Observable` instance gets released from memory it stops observing changes from your storage.
> **Reactive**: Observables can be also observed as Reactive sources using `rx_observe` or `rac_observe`.
In this case there's no need to retain the `Observable` but dispose it whenever you're not interested anymore in observing changes.
### Example project ### Example project
There's an example project available in `Example` folder. There's an example project available in `Example` folder.