File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 11# RxQueryKit
22
3+ [ RxSwift] ( ) extensions for QueryKit.
4+
35## Usage
46
7+ ### QuerySet
8+
9+ RxQueryKit extends QueryKit and provides methods to evaluate and execute
10+ operations as observables.
11+
12+ ``` swift
13+ let queryset = Person.queryset (context).filter (Person.age > 25 )
14+ ```
15+
16+ ``` swift
17+ queryset.objects ().subscribeNext {
18+ print ($0 )
19+ }
20+ ```
21+
22+ ``` swift
23+ queryset.count ().subscribeNext {
24+ print (" There are now \( $0 ) people who are more than 25." )
25+ }
26+ ```
27+
528### Managed Object Context
629
730RxQueryKit provides extensions on managed object context to observe when the
Original file line number Diff line number Diff line change @@ -3,13 +3,18 @@ import RxSwift
33import QueryKit
44
55
6+ /// Extension to QuerySet to provide observables
67extension QuerySet {
8+ /// Performs a query for all objects matching the set predicate ordered by any set sort descriptors.
9+ /// Emits a value with an array of all objects when the managed object context is changed.
710 func objects( ) throws -> Observable < [ ModelType ] > {
811 return context. qk_objectsDidChange ( ) . map { [ unowned self] notification in
912 return try self . array ( )
1013 } . startWith ( try self . array ( ) )
1114 }
1215
16+ /// Performs a query for the count of all objects matching the set predicate.
17+ /// Emits an Int containing the amount of objects matching the predicate and updates when the managed object context is changed.
1318 func count( ) throws -> Observable < Int > {
1419 return context. qk_objectsDidChange ( ) . map { [ unowned self] notification in
1520 return try self . count ( )
You can’t perform that action at this time.
0 commit comments