Skip to content

Commit 07979d2

Browse files
authored
docs: add obj update examples to migration guide
1 parent 93c1619 commit 07979d2

File tree

1 file changed

+90
-2
lines changed

1 file changed

+90
-2
lines changed

MIGRATION.md

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This document describes how to migrate from the [Parse ObjC SDK](https://github.
1212

1313
# Status of the SDKs
1414

15-
The Parse ObjC SDK will be phased out in the future in favor of the more modern Parse Swift SDK. While both SDKs overlap in the ecosystems they serve, they are built conceptually different, which can make migration more challenging. Your milage may vary depending on your use case, we therefore encourage you to migrate as soon as possible.
15+
The Parse ObjC SDK will be phased out in the future in favor of the more modern Parse Swift SDK. While both SDKs overlap in the ecosystems they serve, they are built conceptually different, which can make migration more challenging. Your milage may vary depending on your use case, we therefore encourage you to consider migrating as soon as possible.
1616

1717
# Migration Instructions
1818

@@ -30,7 +30,95 @@ The Parse ObjC SDK will be phased out in the future in favor of the more modern
3030

3131
The issues below are important to consider before migrating.
3232

33-
- ⚠️ Partially updating an object sends the full object to the server; this can have a significant impact on data transfer costs depending on your use case and architecture. All other Parse SDKs including the Parse ObjC SDK only send the changed properties to the server. For details see [GitHub issue #242](https://github.com/parse-community/Parse-Swift/issues/242).
33+
- ⚠️ Partially updating an object sends the complete object (including unchanged properties) to the server if you follow the familiar syntax from the Parse ObjC SDK or any other Parse SDK. This can have a significant impact on data transfer costs depending on your use case and architecture. All other Parse SDKs, including the Parse ObjC SDK, only send the changed properties to the server. The Parse Swift SDK requires a different syntax with additional overhead to achieve the same behavior. For details see [GitHub issue #242](https://github.com/parse-community/Parse-Swift/issues/242).
34+
35+
<details>
36+
<summary>Code Examples</summary>
37+
38+
```
39+
// The following examples compare how to update a saved object in the Parse ObjC SDK
40+
// vs. the Parse Swift SDK. For simplicity, the examples use synchonrous methods.
41+
42+
// Parse ObjC SDK
43+
PFObject *obj = [PFObject objectWithClassName:@"Example"];
44+
obj[@"key"] = @"value1";
45+
[obj save];
46+
obj[@"key"] = @"value2";
47+
[obj save];
48+
49+
// Parse Swift SDK - Variant 1
50+
// This sends the complete object to the server when partially updating the object. This approach
51+
// is not recommended as sending unchanged properties is unnecessary and therefore wastes resources.
52+
struct Example: ParseObject {
53+
var objectId: String?
54+
var createdAt: Date?
55+
var updatedAt: Date?
56+
var ACL: ParseACL?
57+
var originalData: Data?
58+
var key: String?
59+
}
60+
61+
let obj = Example()
62+
obj.key = "value1"
63+
obj.save()
64+
obj.key = "value2"
65+
obj.save()
66+
67+
// Parse Swift SDK - Variant 2
68+
// This sends only the changed properties to the server. Note that `objMergable` only contains the
69+
// modified properties and is missing the unchanged properties. To also contain the unchanged
70+
// properties in addition to the changed properties, an additional `fetch` call on the respective
71+
// object would be necessary. This aproach is not recommended as it adds an additional server
72+
// request to get data that is already present locally. This is unrelated to the limitation that
73+
// any Parse SDK is unaware of any object modification that is done via Cloud Code triggers.
74+
struct Example: ParseObject {
75+
var objectId: String?
76+
var createdAt: Date?
77+
var updatedAt: Date?
78+
var ACL: ParseACL?
79+
var originalData: Data?
80+
var key: String?
81+
}
82+
83+
let obj = Example()
84+
obj.key = "value1"
85+
obj.save()
86+
var objMergable = obj.mergeable
87+
objMergable.key = "value2"
88+
objMergable.save()
89+
90+
// Parse Swift SDK - Variant 3
91+
// This sends only the changed properties to the server. By overriding the `merge` method the
92+
// `objMergable` also contains the unchanged properties of the original `obj`. This means no
93+
// additional `fetch` call is needed. This is the recommned approach which corresponds the most
94+
// with the behavior of the Parse ObjC SDK. Note that any change of custom properies will need
95+
// to reflect in the `merge` method, otherwise `objMergable` may only partially contain the
96+
// original data which leads to data inconsistencies that may be difficult to track down.
97+
struct Example: ParseObject {
98+
var objectId: String?
99+
var createdAt: Date?
100+
var updatedAt: Date?
101+
var ACL: ParseACL?
102+
var originalData: Data?
103+
var key: String?
104+
105+
func merge(with object: Self) throws -> Self {
106+
var updated = try mergeParse(with: object)
107+
if updated.shouldRestoreKey(\.key, original: object) {
108+
updated.key = object.key
109+
}
110+
return updated
111+
}
112+
}
113+
114+
let obj = Example()
115+
obj.key = "value1"
116+
obj.save()
117+
var objMergable = obj.mergeable
118+
objMergable.key = "value2"
119+
objMergable.save()
120+
```
121+
</details>
34122
35123
# Feature Comparison
36124

0 commit comments

Comments
 (0)