Skip to content

Commit 9dea3ca

Browse files
authored
Merge pull request #143 from RxSwiftCommunity/feature/realm-5
Move to realm 5
2 parents 76944c0 + d14209e commit 9dea3ca

File tree

11 files changed

+95
-34
lines changed

11 files changed

+95
-34
lines changed

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Changelog
2+
=========
3+
4+
3.0.0
5+
_____
6+
7+
- added support for Realm 5
8+
- added `queue` optional parameter to `changeset`, `array` and `collection` to specify realm notifications queue

Diff for: Cartfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github "realm/realm-cocoa" ~> 4.0
1+
github "realm/realm-cocoa" ~> 5.0
22
github "ReactiveX/RxSwift" ~> 5.0

Diff for: Cartfile.resolved

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
github "ReactiveX/RxSwift" "5.1.1"
2-
github "realm/realm-cocoa" "v4.4.1"
2+
github "realm/realm-cocoa" "v5.0.0"

Diff for: Example/Podfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use_frameworks!
55
def common
66
pod 'RxSwift', '~> 5.0'
77
pod 'RxCocoa', '~> 5.0'
8-
pod 'RealmSwift', '~> 4.0'
8+
pod 'RealmSwift', '~> 5.0'
99
end
1010

1111
target 'RxRealm_Example' do

Diff for: Example/Podfile.lock

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
PODS:
2-
- Realm (4.0.0):
3-
- Realm/Headers (= 4.0.0)
4-
- Realm/Headers (4.0.0)
5-
- RealmSwift (4.0.0):
6-
- Realm (= 4.0.0)
2+
- Realm (5.0.0):
3+
- Realm/Headers (= 5.0.0)
4+
- Realm/Headers (5.0.0)
5+
- RealmSwift (5.0.0):
6+
- Realm (= 5.0.0)
77
- RxBlocking (5.0.1):
88
- RxSwift (~> 5)
99
- RxCocoa (5.0.1):
1010
- RxRelay (~> 5)
1111
- RxSwift (~> 5)
1212
- RxRealm (2.0.0):
13-
- RealmSwift (~> 4.0)
13+
- RealmSwift (~> 5.0)
1414
- RxSwift (~> 5.0)
1515
- RxRelay (5.0.1):
1616
- RxSwift (~> 5)
1717
- RxSwift (5.0.1)
1818

1919
DEPENDENCIES:
20-
- RealmSwift (~> 4.0)
20+
- RealmSwift (~> 5.0)
2121
- RxBlocking (~> 5.0)
2222
- RxCocoa (~> 5.0)
2323
- RxRealm (from `../`)
@@ -37,14 +37,14 @@ EXTERNAL SOURCES:
3737
:path: "../"
3838

3939
SPEC CHECKSUMS:
40-
Realm: 0c5b8f398daeec5b29824e41c453ff9e126e31d8
41-
RealmSwift: 02e1f604f7091ec535145055764ca53efa8cdc92
40+
Realm: 76066d333de26f97e9caedaa85ee3ff4a62ca265
41+
RealmSwift: c1bdff09b422569dc6881410d9ccf712bcdb79b0
4242
RxBlocking: c5e090f42d046df8b0e7752742510f349963710f
4343
RxCocoa: e741b9749968e8a143e2b787f1dfbff2b63d0a5c
44-
RxRealm: 900f5c7e6f0a2d6527b56eaf7283f3035ec1e8ba
44+
RxRealm: e3dedde1087480209362d91fe51d4ca5b24a8eed
4545
RxRelay: 89d54507f4fd4d969e6ec1d4bd7f3673640b4640
4646
RxSwift: e2dc62b366a3adf6a0be44ba9f405efd4c94e0c4
4747

48-
PODFILE CHECKSUM: 8a7e6d13cb4c3aac7bdbe6b14488098a21a9902f
48+
PODFILE CHECKSUM: a78ac0903554ff2c7c096d6027ef4c90f9202ec7
4949

50-
COCOAPODS: 1.8.4
50+
COCOAPODS: 1.9.1

Diff for: Example/RxRealm.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; };
1313
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
1414
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
15+
78E7A8FC2472985A00436C69 /* RxRealmOnQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E7A8FB2472985A00436C69 /* RxRealmOnQueueTests.swift */; };
1516
9C45F1041FD014B0009D5EFF /* RxRealmWriteSinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C3182361D02BAA90003F1EB /* RxRealmWriteSinks.swift */; };
1617
9C4FE0611DC7B1FD00DF66A5 /* RxRealmObjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C4FE0601DC7B1FD00DF66A5 /* RxRealmObjectTests.swift */; };
1718
9CBA07791CD4A5FA00ABF96E /* RxRealmResultsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CBA07781CD4A5FA00ABF96E /* RxRealmResultsTests.swift */; };
@@ -46,6 +47,7 @@
4647
607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
4748
69534DCD3B8D6B4BAB868A82 /* Pods-RxRealm_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxRealm_Tests.debug.xcconfig"; path = "Target Support Files/Pods-RxRealm_Tests/Pods-RxRealm_Tests.debug.xcconfig"; sourceTree = "<group>"; };
4849
74D9A8127363946A03ABDCFB /* RxRealm.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = RxRealm.podspec; path = ../RxRealm.podspec; sourceTree = "<group>"; };
50+
78E7A8FB2472985A00436C69 /* RxRealmOnQueueTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxRealmOnQueueTests.swift; sourceTree = "<group>"; };
4951
86326B85BB9E5A8FF6DCBD1E /* Pods-RxRealm_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxRealm_Tests.release.xcconfig"; path = "Target Support Files/Pods-RxRealm_Tests/Pods-RxRealm_Tests.release.xcconfig"; sourceTree = "<group>"; };
5052
9C3182361D02BAA90003F1EB /* RxRealmWriteSinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxRealmWriteSinks.swift; sourceTree = "<group>"; };
5153
9C4FE0601DC7B1FD00DF66A5 /* RxRealmObjectTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxRealmObjectTests.swift; sourceTree = "<group>"; };
@@ -159,6 +161,7 @@
159161
9CFB8DC11CF22BA4004BC090 /* RxRealmRealmTests.swift */,
160162
9C4FE0601DC7B1FD00DF66A5 /* RxRealmObjectTests.swift */,
161163
9CEB7A4B1CC834340077C44D /* Info.plist */,
164+
78E7A8FB2472985A00436C69 /* RxRealmOnQueueTests.swift */,
162165
);
163166
name = RxRealmTests;
164167
path = RxRealm_Tests;
@@ -379,6 +382,7 @@
379382
9CEC5B381CD6942E00B43868 /* RxRealmLinkingObjectsTests.swift in Sources */,
380383
9CBA077C1CD4A68000ABF96E /* TestModels.swift in Sources */,
381384
9CEC5B361CD692A600B43868 /* RxRealmListTests.swift in Sources */,
385+
78E7A8FC2472985A00436C69 /* RxRealmOnQueueTests.swift in Sources */,
382386
);
383387
runOnlyForDeploymentPostprocessing = 0;
384388
};

Diff for: Example/RxRealm_Tests/RxRealmOnQueueTests.swift

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// RxRealmOnQueueTests.swift
3+
// RxRealm_Tests
4+
//
5+
// Created by Anton Nazarov on 18.05.2020.
6+
// Copyright © 2020 CocoaPods. All rights reserved.
7+
//
8+
9+
import XCTest
10+
import RxSwift
11+
import RealmSwift
12+
13+
final class RxRealmOnQueueTests: XCTestCase {
14+
func testCollectionOnQueue() {
15+
verifyObservableEmitOnBackground {
16+
Observable.collection(from: $0, synchronousStart: false, on: DispatchQueue(label: #function))
17+
}
18+
}
19+
20+
func testArrayOnQueue() {
21+
verifyObservableEmitOnBackground {
22+
Observable.array(from: $0, synchronousStart: false, on: DispatchQueue(label: #function))
23+
}
24+
}
25+
26+
func testChangesetOnQueue() {
27+
verifyObservableEmitOnBackground {
28+
Observable.changeset(from: $0, synchronousStart: false, on: DispatchQueue(label: #function))
29+
}
30+
}
31+
32+
private func verifyObservableEmitOnBackground<Element>(factory: (Results<UniqueObject>) -> Observable<Element>) {
33+
let realm = realmInMemory()
34+
DispatchQueue.main.async {
35+
try! realm.write {
36+
realm.add(UniqueObject(1))
37+
}
38+
}
39+
let dispatchedOnMainTread = try! factory(realm.objects(UniqueObject.self))
40+
.map { _ in Thread.isMainThread }
41+
.toBlocking(timeout: 2)
42+
.first()
43+
XCTAssertFalse(dispatchedOnMainTread!)
44+
}
45+
}

Diff for: Package.resolved

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
"repositoryURL": "https://github.com/realm/realm-cocoa.git",
77
"state": {
88
"branch": null,
9-
"revision": "fa43b8e2909334c79f233ce472332c136ca108da",
10-
"version": "4.4.1"
9+
"revision": "91dc97e014134ecddef28d2bab7c74648e8937f3",
10+
"version": "5.0.0"
1111
}
1212
},
1313
{
1414
"package": "RealmCore",
1515
"repositoryURL": "https://github.com/realm/realm-core",
1616
"state": {
1717
"branch": null,
18-
"revision": "35662ff940e340bf630ad1d1d88acfc7af18bee6",
19-
"version": "5.23.8"
18+
"revision": "3735ee940583f3d62f73076034505ff4e6207d91",
19+
"version": "6.0.4"
2020
}
2121
},
2222
{

Diff for: Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let package = Package(
88
],
99
dependencies: [
1010
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "5.0.0")),
11-
.package(url: "https://github.com/realm/realm-cocoa.git", .upToNextMajor(from: "4.0.0"))
11+
.package(url: "https://github.com/realm/realm-cocoa.git", .upToNextMajor(from: "5.0.0"))
1212
],
1313
targets: [
1414
.target(

Diff for: Pod/Classes/RxRealm.swift

+16-12
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public protocol NotificationEmitter {
3232

3333
- returns: `NotificationToken` - retain this value to keep notifications being emitted for the current collection.
3434
*/
35-
func observe(_ block: @escaping (RealmCollectionChange<Self>) -> Void) -> NotificationToken
35+
func observe(on queue: DispatchQueue?, _ block: @escaping (RealmCollectionChange<Self>) -> Void) -> NotificationToken
3636

3737
func toArray() -> [ElementType]
3838

@@ -111,17 +111,18 @@ public extension ObservableType where Element: NotificationEmitter {
111111

112112
- parameter from: A Realm collection of type `Element`: either `Results`, `List`, `LinkingObjects` or `AnyRealmCollection`.
113113
- parameter synchronousStart: whether the resulting `Observable` should emit its first element synchronously (e.g. better for UI bindings)
114+
- parameter queue: The serial dispatch queue to receive notification on. If `nil`, notifications are delivered to the current thread.
114115

115116
- returns: `Observable<Element>`, e.g. when called on `Results<Model>` it will return `Observable<Results<Model>>`, on a `List<User>` it will return `Observable<List<User>>`, etc.
116117
*/
117-
static func collection(from collection: Element, synchronousStart: Bool = true)
118+
static func collection(from collection: Element, synchronousStart: Bool = true, on queue: DispatchQueue? = nil)
118119
-> Observable<Element> {
119120
return Observable.create { observer in
120121
if synchronousStart {
121122
observer.onNext(collection)
122123
}
123124

124-
let token = collection.observe { changeset in
125+
let token = collection.observe(on: queue) { changeset in
125126

126127
let value: Element
127128

@@ -158,12 +159,13 @@ public extension ObservableType where Element: NotificationEmitter {
158159

159160
- parameter from: A Realm collection of type `Element`: either `Results`, `List`, `LinkingObjects` or `AnyRealmCollection`.
160161
- parameter synchronousStart: whether the resulting Observable should emit its first element synchronously (e.g. better for UI bindings)
162+
- parameter queue: The serial dispatch queue to receive notification on. If `nil`, notifications are delivered to the current thread.
161163

162164
- returns: `Observable<Array<Element.Element>>`, e.g. when called on `Results<Model>` it will return `Observable<Array<Model>>`, on a `List<User>` it will return `Observable<Array<User>>`, etc.
163165
*/
164-
static func array(from collection: Element, synchronousStart: Bool = true)
166+
static func array(from collection: Element, synchronousStart: Bool = true, on queue: DispatchQueue? = nil)
165167
-> Observable<[Element.ElementType]> {
166-
return Observable.collection(from: collection, synchronousStart: synchronousStart)
168+
return Observable.collection(from: collection, synchronousStart: synchronousStart, on: queue)
167169
.map { $0.toArray() }
168170
}
169171

@@ -181,17 +183,18 @@ public extension ObservableType where Element: NotificationEmitter {
181183

182184
- parameter from: A Realm collection of type `Element`: either `Results`, `List`, `LinkingObjects` or `AnyRealmCollection`.
183185
- parameter synchronousStart: whether the resulting Observable should emit its first element synchronously (e.g. better for UI bindings)
186+
- parameter queue: The serial dispatch queue to receive notification on. If `nil`, notifications are delivered to the current thread.
184187

185188
- returns: `Observable<(AnyRealmCollection<Element.Element>, RealmChangeset?)>`
186189
*/
187-
static func changeset(from collection: Element, synchronousStart: Bool = true)
190+
static func changeset(from collection: Element, synchronousStart: Bool = true, on queue: DispatchQueue? = nil)
188191
-> Observable<(AnyRealmCollection<Element.ElementType>, RealmChangeset?)> {
189192
return Observable.create { observer in
190193
if synchronousStart {
191194
observer.onNext((collection.toAnyCollection(), nil))
192195
}
193196

194-
let token = collection.toAnyCollection().observe { changeset in
197+
let token = collection.toAnyCollection().observe(on: queue) { changeset in
195198

196199
switch changeset {
197200
case let .initial(value):
@@ -227,12 +230,13 @@ public extension ObservableType where Element: NotificationEmitter {
227230

228231
- parameter from: A Realm collection of type `Element`: either `Results`, `List`, `LinkingObjects` or `AnyRealmCollection`.
229232
- parameter synchronousStart: whether the resulting Observable should emit its first element synchronously (e.g. better for UI bindings)
233+
- parameter queue: The serial dispatch queue to receive notification on. If `nil`, notifications are delivered to the current thread.
230234

231235
- returns: `Observable<(Array<Element.Element>, RealmChangeset?)>`
232236
*/
233-
static func arrayWithChangeset(from collection: Element, synchronousStart: Bool = true)
237+
static func arrayWithChangeset(from collection: Element, synchronousStart: Bool = true, on queue: DispatchQueue? = nil)
234238
-> Observable<([Element.ElementType], RealmChangeset?)> {
235-
return Observable.changeset(from: collection)
239+
return Observable.changeset(from: collection, on: queue)
236240
.map { ($0.toArray(), $1) }
237241
}
238242
}
@@ -510,8 +514,8 @@ public extension Observable where Element: Object {
510514

511515
let token = object.observe { change in
512516
switch change {
513-
case let .change(changedProperties):
514-
if let properties = properties, !changedProperties.contains { return properties.contains($0.name) } {
517+
case let .change(_, changedProperties):
518+
if let properties = properties, !changedProperties.contains(where: { properties.contains($0.name) }) {
515519
// if change property isn't an observed one, just return
516520
return
517521
}
@@ -540,7 +544,7 @@ public extension Observable where Element: Object {
540544
return Observable<PropertyChange>.create { observer in
541545
let token = object.observe { change in
542546
switch change {
543-
case let .change(changes):
547+
case let .change(_, changes):
544548
for change in changes {
545549
observer.onNext(change)
546550
}

Diff for: RxRealm.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "RxRealm"
4-
s.version = "2.0.0"
4+
s.version = "3.0.0"
55
s.summary = "An Rx wrapper of Realm's notifications and write bindings"
66
s.swift_version = "5.0"
77

@@ -25,7 +25,7 @@ Pod::Spec.new do |s|
2525
s.source_files = 'Pod/Classes/*.swift'
2626

2727
s.frameworks = 'Foundation'
28-
s.dependency 'RealmSwift', '~> 4.0'
28+
s.dependency 'RealmSwift', '~> 5.0'
2929
s.dependency 'RxSwift', '~> 5.0'
3030

3131
end

0 commit comments

Comments
 (0)