File tree 3 files changed +9
-15
lines changed
3 files changed +9
-15
lines changed Original file line number Diff line number Diff line change @@ -77,23 +77,23 @@ extension CKRecordRecoverable where Self: Object {
77
77
if let existObject = realm. object ( ofType: U . self, forPrimaryKey: primaryKeyValue) {
78
78
uList. append ( existObject)
79
79
} else {
80
- pendingUTypeRelationshipsWorker. addToPendingListElement ( propertyName: prop. name, primaryKeyValue : primaryKeyValue )
80
+ pendingUTypeRelationshipsWorker. addToPendingList ( elementPrimaryKeyValue : primaryKeyValue , propertyName: prop. name, owner : o )
81
81
}
82
82
}
83
83
84
84
if schema. className == V . className ( ) {
85
85
if let existObject = realm. object ( ofType: V . self, forPrimaryKey: primaryKeyValue) {
86
86
vList. append ( existObject)
87
87
} else {
88
- pendingVTypeRelationshipsWorker. addToPendingListElement ( propertyName: prop. name, primaryKeyValue : primaryKeyValue )
88
+ pendingVTypeRelationshipsWorker. addToPendingList ( elementPrimaryKeyValue : primaryKeyValue , propertyName: prop. name, owner : o )
89
89
}
90
90
}
91
91
92
92
if schema. className == W . className ( ) {
93
93
if let existObject = realm. object ( ofType: W . self, forPrimaryKey: primaryKeyValue) {
94
94
wList. append ( existObject)
95
95
} else {
96
- pendingWTypeRelationshipsWorker. addToPendingListElement ( propertyName: prop. name, primaryKeyValue : primaryKeyValue )
96
+ pendingWTypeRelationshipsWorker. addToPendingList ( elementPrimaryKeyValue : primaryKeyValue , propertyName: prop. name, owner : o )
97
97
}
98
98
}
99
99
Original file line number Diff line number Diff line change 8
8
import Foundation
9
9
import RealmSwift
10
10
11
+ /// PendingRelationshipsWorker is responsible for temporarily storing relationships when objects recovering from CKRecord
11
12
final class PendingRelationshipsWorker < Element: Object > {
12
13
13
14
var realm : Realm ?
14
- var owner : Object ?
15
15
16
- var pendingListElementPrimaryKeyValue : [ AnyHashable : String ] = [ : ]
16
+ var pendingListElementPrimaryKeyValue : [ AnyHashable : ( String , Object ) ] = [ : ]
17
17
18
- func addToPendingListElement ( propertyName: String , primaryKeyValue : AnyHashable ) {
19
- pendingListElementPrimaryKeyValue [ primaryKeyValue ] = propertyName
18
+ func addToPendingList ( elementPrimaryKeyValue : AnyHashable , propertyName: String , owner : Object ) {
19
+ pendingListElementPrimaryKeyValue [ elementPrimaryKeyValue ] = ( propertyName, owner )
20
20
}
21
21
22
22
func resolvePendingListElements( ) {
23
- guard let owner = owner , let realm = realm, pendingListElementPrimaryKeyValue. count > 0 else {
23
+ guard let realm = realm, pendingListElementPrimaryKeyValue. count > 0 else {
24
24
// Maybe we could add one log here
25
25
return
26
26
}
27
27
BackgroundWorker . shared. start {
28
- for (primaryKeyValue, propName) in self . pendingListElementPrimaryKeyValue {
28
+ for (primaryKeyValue, ( propName, owner ) ) in self . pendingListElementPrimaryKeyValue {
29
29
guard let list = owner. value ( forKey: propName) as? List < Element > else { return }
30
30
if let existListElementObject = realm. object ( ofType: Element . self, forPrimaryKey: primaryKeyValue) {
31
31
try ! realm. write {
Original file line number Diff line number Diff line change @@ -94,14 +94,8 @@ extension SyncObject: Syncable {
94
94
print ( " There is something wrong with the converson from cloud record to local object " )
95
95
return
96
96
}
97
-
98
- self . pendingUTypeRelationshipsWorker. owner = object
99
97
self . pendingUTypeRelationshipsWorker. realm = realm
100
-
101
- self . pendingVTypeRelationshipsWorker. owner = object
102
98
self . pendingVTypeRelationshipsWorker. realm = realm
103
-
104
- self . pendingWTypeRelationshipsWorker. owner = object
105
99
self . pendingWTypeRelationshipsWorker. realm = realm
106
100
107
101
/// If your model class includes a primary key, you can have Realm intelligently update or add objects based off of their primary key values using Realm().add(_:update:).
You can’t perform that action at this time.
0 commit comments