Skip to content

Commit 8245f9e

Browse files
authored
feat: add set() and auto merge updated properties with original (#406)
* wip * updates * feat: add set() and auto merge updated properties with original * updates * update documentation and tests
1 parent a94ac8c commit 8245f9e

16 files changed

+556
-143
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.10.0...main)
55
* _Contributing to this repo? Add info about your change here to be included in the next release_
66

7+
### 4.11.0
8+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.10.0...4.11.0)
9+
10+
__New features__
11+
- Add a set method that developers can call on their ParseObjects which automatically sends updated properties to a Parse Server and merges those updates with the original ParseObject locally. The feature removes the requirement to call mergeable and implement merge(), but comes at additional computational overhead ([#406](https://github.com/parse-community/Parse-Swift/pull/406)), thanks to [Corey Baker](https://github.com/cbaker6).
12+
713
### 4.10.0
814
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.9.3...4.10.0)
915

ParseSwift.xcodeproj/project.pbxproj

-10
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,6 @@
451451
7085DDB326D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7085DDB226D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift */; };
452452
7085DDB426D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7085DDB226D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift */; };
453453
7085DDB526D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7085DDB226D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift */; };
454-
7087A93C28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7087A93B28C558CA00656E93 /* ParseOperation+keyPath.swift */; };
455-
7087A93D28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7087A93B28C558CA00656E93 /* ParseOperation+keyPath.swift */; };
456-
7087A93E28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7087A93B28C558CA00656E93 /* ParseOperation+keyPath.swift */; };
457-
7087A93F28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7087A93B28C558CA00656E93 /* ParseOperation+keyPath.swift */; };
458454
708CADCF2872263D0066C279 /* ParseKeychainAccessGroupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 708CADCE2872263D0066C279 /* ParseKeychainAccessGroupTests.swift */; };
459455
708CADD02872263D0066C279 /* ParseKeychainAccessGroupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 708CADCE2872263D0066C279 /* ParseKeychainAccessGroupTests.swift */; };
460456
708CADD12872263D0066C279 /* ParseKeychainAccessGroupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 708CADCE2872263D0066C279 /* ParseKeychainAccessGroupTests.swift */; };
@@ -1273,7 +1269,6 @@
12731269
7085DD9326CBF3A70033B977 /* Documentation.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = Documentation.docc; sourceTree = "<group>"; };
12741270
7085DDA226CC8A470033B977 /* ParseHealth+combine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ParseHealth+combine.swift"; sourceTree = "<group>"; };
12751271
7085DDB226D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseAuthenticationCombineTests.swift; sourceTree = "<group>"; };
1276-
7087A93B28C558CA00656E93 /* ParseOperation+keyPath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ParseOperation+keyPath.swift"; sourceTree = "<group>"; };
12771272
708CADCE2872263D0066C279 /* ParseKeychainAccessGroupTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseKeychainAccessGroupTests.swift; sourceTree = "<group>"; };
12781273
708D035125215F9B00646C70 /* Deletable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deletable.swift; sourceTree = "<group>"; };
12791274
709A147C283949D100BF85E5 /* ParseSchema.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseSchema.swift; sourceTree = "<group>"; };
@@ -2140,7 +2135,6 @@
21402135
F97B464024D9C78B00F4A88B /* ParseOperation.swift */,
21412136
703B091026BD992E005A112F /* ParseOperation+async.swift */,
21422137
7044C19E25C4FA870011F6E7 /* ParseOperation+combine.swift */,
2143-
7087A93B28C558CA00656E93 /* ParseOperation+keyPath.swift */,
21442138
91285B1B26990D7F0051B544 /* ParsePolygon.swift */,
21452139
705025BC284C610C008D6624 /* ParsePush.swift */,
21462140
705025C1284C7841008D6624 /* ParsePush+async.swift */,
@@ -2703,7 +2697,6 @@
27032697
91285B1C26990D7F0051B544 /* ParsePolygon.swift in Sources */,
27042698
91BB8FCA2690AC99005A6BA5 /* QueryViewModel.swift in Sources */,
27052699
7085DD9426CBF3A70033B977 /* Documentation.docc in Sources */,
2706-
7087A93C28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */,
27072700
705025EB285153BC008D6624 /* ParsePushApplePayloadable.swift in Sources */,
27082701
705025A928441C96008D6624 /* ParseFieldOptions.swift in Sources */,
27092702
F97B45D624D9C6F200F4A88B /* ParseEncoder.swift in Sources */,
@@ -3013,7 +3006,6 @@
30133006
91285B1D26990D7F0051B544 /* ParsePolygon.swift in Sources */,
30143007
91BB8FCB2690AC99005A6BA5 /* QueryViewModel.swift in Sources */,
30153008
7085DD9526CBF3A70033B977 /* Documentation.docc in Sources */,
3016-
7087A93D28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */,
30173009
705025EC285153BC008D6624 /* ParsePushApplePayloadable.swift in Sources */,
30183010
705025AA28441C96008D6624 /* ParseFieldOptions.swift in Sources */,
30193011
F97B45D724D9C6F200F4A88B /* ParseEncoder.swift in Sources */,
@@ -3455,7 +3447,6 @@
34553447
91679D67268E596300F71809 /* ParseVersion.swift in Sources */,
34563448
91285B1F26990D7F0051B544 /* ParsePolygon.swift in Sources */,
34573449
91BB8FCD2690AC99005A6BA5 /* QueryViewModel.swift in Sources */,
3458-
7087A93F28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */,
34593450
705025EE285153BC008D6624 /* ParsePushApplePayloadable.swift in Sources */,
34603451
705025AC28441C96008D6624 /* ParseFieldOptions.swift in Sources */,
34613452
7085DD9726CBF3A70033B977 /* Documentation.docc in Sources */,
@@ -3642,7 +3633,6 @@
36423633
91679D66268E596300F71809 /* ParseVersion.swift in Sources */,
36433634
91285B1E26990D7F0051B544 /* ParsePolygon.swift in Sources */,
36443635
91BB8FCC2690AC99005A6BA5 /* QueryViewModel.swift in Sources */,
3645-
7087A93E28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */,
36463636
705025ED285153BC008D6624 /* ParsePushApplePayloadable.swift in Sources */,
36473637
705025AB28441C96008D6624 /* ParseFieldOptions.swift in Sources */,
36483638
7085DD9626CBF3A70033B977 /* Documentation.docc in Sources */,

Sources/ParseSwift/API/API+Command.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -430,17 +430,17 @@ internal extension API.Command {
430430
let mapper = { (mapperData: Data) -> T in
431431
var updatedObject = object
432432
updatedObject.originalData = nil
433-
let object = try ParseCoding
433+
updatedObject = try ParseCoding
434434
.jsonDecoder()
435435
.decode(ReplaceResponse.self, from: mapperData)
436436
.apply(to: updatedObject)
437437
guard let originalData = data,
438438
let original = try? ParseCoding.jsonDecoder().decode(T.self,
439439
from: originalData),
440-
original.hasSameObjectId(as: object) else {
441-
return object
440+
original.hasSameObjectId(as: updatedObject) else {
441+
return updatedObject
442442
}
443-
return try object.merge(with: original)
443+
return try updatedObject.merge(with: original)
444444
}
445445
return API.Command<T, T>(method: .PUT,
446446
path: object.endpoint,
@@ -456,17 +456,17 @@ internal extension API.Command {
456456
let mapper = { (mapperData: Data) -> T in
457457
var updatedObject = object
458458
updatedObject.originalData = nil
459-
let object = try ParseCoding
459+
updatedObject = try ParseCoding
460460
.jsonDecoder()
461461
.decode(UpdateResponse.self, from: mapperData)
462462
.apply(to: updatedObject)
463463
guard let originalData = data,
464464
let original = try? ParseCoding.jsonDecoder().decode(T.self,
465465
from: originalData),
466-
original.hasSameObjectId(as: object) else {
467-
return object
466+
original.hasSameObjectId(as: updatedObject) else {
467+
return updatedObject
468468
}
469-
return try object.merge(with: original)
469+
return try updatedObject.merge(with: original)
470470
}
471471
return API.Command<T, T>(method: .PATCH,
472472
path: object.endpoint,

Sources/ParseSwift/Objects/ParseInstallation.swift

+15-9
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ public extension ParseInstallation {
153153
}
154154

155155
func merge(with object: Self) throws -> Self {
156-
try mergeParse(with: object)
156+
do {
157+
return try mergeAutomatically(object)
158+
} catch {
159+
return try mergeParse(with: object)
160+
}
157161
}
158162
}
159163

@@ -773,15 +777,16 @@ extension ParseInstallation {
773777
let mapper = { (data: Data) -> Self in
774778
var updatedObject = self
775779
updatedObject.originalData = nil
776-
let object = try ParseCoding.jsonDecoder().decode(ReplaceResponse.self, from: data).apply(to: updatedObject)
780+
updatedObject = try ParseCoding.jsonDecoder().decode(ReplaceResponse.self,
781+
from: data).apply(to: updatedObject)
777782
// MARK: The lines below should be removed when server supports PATCH.
778783
guard let originalData = self.originalData,
779784
let original = try? ParseCoding.jsonDecoder().decode(Self.self,
780785
from: originalData),
781-
original.hasSameObjectId(as: object) else {
782-
return object
786+
original.hasSameObjectId(as: updatedObject) else {
787+
return updatedObject
783788
}
784-
return try object.merge(with: original)
789+
return try updatedObject.merge(with: original)
785790
}
786791
return API.Command<Self, Self>(method: .PUT,
787792
path: endpoint,
@@ -797,14 +802,15 @@ extension ParseInstallation {
797802
let mapper = { (data: Data) -> Self in
798803
var updatedObject = self
799804
updatedObject.originalData = nil
800-
let object = try ParseCoding.jsonDecoder().decode(UpdateResponse.self, from: data).apply(to: updatedObject)
805+
updatedObject = try ParseCoding.jsonDecoder().decode(UpdateResponse.self,
806+
from: data).apply(to: updatedObject)
801807
guard let originalData = self.originalData,
802808
let original = try? ParseCoding.jsonDecoder().decode(Self.self,
803809
from: originalData),
804-
original.hasSameObjectId(as: object) else {
805-
return object
810+
original.hasSameObjectId(as: updatedObject) else {
811+
return updatedObject
806812
}
807-
return try object.merge(with: original)
813+
return try updatedObject.merge(with: original)
808814
}
809815
return API.Command<Self, Self>(method: .PATCH,
810816
path: endpoint,

0 commit comments

Comments
 (0)