File tree 2 files changed +11
-2
lines changed
2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ extension CKRecordRecoverable where Self: Object {
76
76
if let asset = record. value ( forKey: prop. name) as? CKAsset {
77
77
recordValue = CreamAsset . parse ( from: prop. name, record: record, asset: asset)
78
78
} else if let owner = record. value ( forKey: prop. name) as? CKRecord . Reference , let ownerType = prop. objectClassName {
79
- recordValue = realm. dynamicObject ( ofType: ownerType, forPrimaryKey: owner. recordID. recordName )
79
+ recordValue = realm. dynamicObject ( ofType: ownerType, forPrimaryKey: primaryKeyForRecordID ( recordID : owner. recordID) )
80
80
// Because we use the primaryKey as recordName when object converting to CKRecord
81
81
}
82
82
default :
@@ -88,4 +88,13 @@ extension CKRecordRecoverable where Self: Object {
88
88
}
89
89
return o
90
90
}
91
+
92
+ /// The primaryKey in Realm could be type of Int or String. However the `recordName` is a String type, we need to make a check.
93
+ /// The reversed process happens in `recordID` property in `CKRecordConvertible` protocol.
94
+ ///
95
+ /// - Parameter recordID: the recordID that CloudKit sent to us
96
+ /// - Returns: the specific value of primaryKey in Realm
97
+ static func primaryKeyForRecordID( recordID: CKRecord . ID ) -> Any {
98
+ return Int ( recordID. recordName) ?? recordID. recordName
99
+ }
91
100
}
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ extension SyncObject: Syncable {
91
91
92
92
public func delete( recordID: CKRecord . ID ) {
93
93
DispatchQueue . main. async {
94
- guard let object = self . realm. object ( ofType: T . self, forPrimaryKey: recordID . recordName ) else {
94
+ guard let object = self . realm. object ( ofType: T . self, forPrimaryKey: T . primaryKeyForRecordID ( recordID : recordID ) ) else {
95
95
// Not found in local realm database
96
96
return
97
97
}
You can’t perform that action at this time.
0 commit comments