Skip to content

Commit 5d03b9b

Browse files
committed
Implement basic observable QuerySet
1 parent 84493c4 commit 5d03b9b

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

RxQueryKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
270A33171B9C04DB00AEE90E /* RxQueryKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 270A33161B9C04DB00AEE90E /* RxQueryKitTests.swift */; };
1313
270A33221B9C07B100AEE90E /* RxManagedObjectContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 270A33211B9C07B100AEE90E /* RxManagedObjectContext.swift */; settings = {ASSET_TAGS = (); }; };
1414
270A33241B9C09A500AEE90E /* RxManagedObjectContextTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 270A33231B9C09A500AEE90E /* RxManagedObjectContextTests.swift */; settings = {ASSET_TAGS = (); }; };
15+
270A33261B9C105000AEE90E /* RxQueryKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 270A33251B9C105000AEE90E /* RxQueryKit.swift */; settings = {ASSET_TAGS = (); }; };
1516
63FD81FDCFE39B3CDFDF0774 /* Pods_RxQueryKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C8F2DEC34DCEF2E7340DBC7E /* Pods_RxQueryKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
1617
FA80A9986F4F0DEDE3B0CEBF /* Pods_RxQueryKitTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49C94D6480DB8DB97DDCE442 /* Pods_RxQueryKitTests.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
1718
/* End PBXBuildFile section */
@@ -38,6 +39,7 @@
3839
270A33181B9C04DB00AEE90E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3940
270A33211B9C07B100AEE90E /* RxManagedObjectContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxManagedObjectContext.swift; sourceTree = "<group>"; };
4041
270A33231B9C09A500AEE90E /* RxManagedObjectContextTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxManagedObjectContextTests.swift; sourceTree = "<group>"; };
42+
270A33251B9C105000AEE90E /* RxQueryKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxQueryKit.swift; sourceTree = "<group>"; };
4143
49C94D6480DB8DB97DDCE442 /* Pods_RxQueryKitTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RxQueryKitTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4244
6CD66E6607DEF2A439FE0BF4 /* Pods-RxQueryKit.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxQueryKit.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RxQueryKit/Pods-RxQueryKit.debug.xcconfig"; sourceTree = "<group>"; };
4345
C8F2DEC34DCEF2E7340DBC7E /* Pods_RxQueryKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RxQueryKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -88,6 +90,7 @@
8890
isa = PBXGroup;
8991
children = (
9092
270A330A1B9C04DB00AEE90E /* RxQueryKit.h */,
93+
270A33251B9C105000AEE90E /* RxQueryKit.swift */,
9194
270A33211B9C07B100AEE90E /* RxManagedObjectContext.swift */,
9295
270A330C1B9C04DB00AEE90E /* Info.plist */,
9396
);
@@ -316,6 +319,7 @@
316319
buildActionMask = 2147483647;
317320
files = (
318321
270A33221B9C07B100AEE90E /* RxManagedObjectContext.swift in Sources */,
322+
270A33261B9C105000AEE90E /* RxQueryKit.swift in Sources */,
319323
);
320324
runOnlyForDeploymentPostprocessing = 0;
321325
};

RxQueryKit/RxManagedObjectContext.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
import CoreData
22
import RxSwift
33

4-
/*
5-
@available(OSX 10.4, *)
6-
public let NSInsertedObjectsKey: String
7-
@available(OSX 10.4, *)
8-
public let NSUpdatedObjectsKey: String
9-
@available(OSX 10.4, *)
10-
public let NSDeletedObjectsKey: String
114

12-
@available(OSX 10.5, *)
13-
public let NSRefreshedObjectsKey: String
14-
@available(OSX 10.5, *)
15-
public let NSInvalidatedObjectsKey: String
16-
17-
// User info keys for NSManagedObjectContextObjectsDidChangeNotification: the values for these keys are arrays of objectIDs
18-
@available(OSX 10.5, *)
19-
public let NSInvalidatedAllObjectsKey: String // All objects in the context have been invalidated
20-
*/
215
extension NSNotificationCenter {
226
func rx_notification(name: String, object: AnyObject?) -> Observable<NSNotification> {
237
return AnonymousObservable { observer in

RxQueryKit/RxQueryKit.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import CoreData
2+
import RxSwift
3+
import QueryKit
4+
5+
6+
extension QuerySet {
7+
func objects() throws -> Observable<[ModelType]> {
8+
return context.qk_objectsDidChange().map { [unowned self] notification in
9+
return try self.array()
10+
}.startWith(try self.array())
11+
}
12+
13+
func count() throws -> Observable<Int> {
14+
return context.qk_objectsDidChange().map { [unowned self] notification in
15+
return try self.count()
16+
}.startWith(try self.count())
17+
}
18+
}

0 commit comments

Comments
 (0)