@@ -12,19 +12,63 @@ import Foundation
12
12
Objects that conform to the `ParseObject` protocol have a local representation of data persisted to the Parse cloud.
13
13
This is the main protocol that is used to interact with objects in your app.
14
14
15
- If you plan to use custom encoding/decoding, be sure to add `objectId`, `createdAt`, `updatedAt`, and
16
- `ACL` to your `ParseObject` `CodingKeys`.
15
+ The Swift SDK is designed for your `ParseObject`s to be "value types" (structs).
16
+ If you are using value types the the compiler will assist you with conforming to `ParseObject` protocol. If you
17
+ are thinking of using reference types, see the warning.
18
+
19
+ It's recommended the developer adds the emptyObject computed property or similar.
20
+ Gets an empty version of the respective object. This can be used when you only need to update a
21
+ a subset of the fields of an object as oppose to updating every field of an object. Using an empty object and updating
22
+ a subset of the fields reduces the amount of data sent between client and server when using `save` and `saveAll`
23
+ to update objects. You should add the following properties in your `ParseObject`'s:
24
+
25
+ var emptyObject: Self {
26
+ var object = Self()
27
+ object.objectId = objectId
28
+ object.createdAt = createdAt
29
+ return object
30
+ }
31
+
32
+ When designing applications for SwiftUI, it is recommended to make all `ParseObject`'s conform to
33
+ `Identifiable`. This can be accomplised by doing the following:
17
34
18
- - note: It is recommended to make your`ParseObject`s "value types" (structs).
19
- If you are using value types there isn't much else you need to do but to conform to ParseObject. If you are thinking of
20
- using reference types, see the warning.
35
+ struct GameScore: ParseObject, Identifiable {
36
+
37
+ // Add this computed property to conform to `Identifiable` for iOS13+
38
+ var id: String {
39
+ guard let objectId = self.objectId else {
40
+ return UUID().uuidString
41
+ }
42
+ return objectId
43
+ }
44
+
45
+ // These are required for any Object.
46
+ var objectId: String?
47
+ var createdAt: Date?
48
+ var updatedAt: Date?
49
+ var ACL: ParseACL?
50
+
51
+ // Your own properties.
52
+ var score: Int = 0
53
+ var location: ParseGeoPoint?
54
+ var name: String?
55
+ var myFiles: [ParseFile]?
56
+ }
57
+
58
+ - important: It is recommended that all added properties be optional properties so they can eventually be used as
59
+ Parse `Pointer`'s. If a developer really wants to have a required key, they should require it on the server-side or
60
+ create methods to check the respective properties on the client-side before saving objects. See
61
+ [here](https://github.com/parse-community/Parse-Swift/issues/157#issuecomment-858671025)
62
+ for more information.
21
63
- warning: If you plan to use "reference types" (classes), you are using at your risk as this SDK is not designed
22
64
for reference types and may have unexpected behavior when it comes to threading. You will also need to implement
23
65
your own `==` method to conform to `Equatable` along with with the `hash` method to conform to `Hashable`.
24
66
It is important to note that for unsaved `ParseObject`'s, you won't be able to rely on `objectId` for
25
67
`Equatable` and `Hashable` as your unsaved objects won't have this value yet and is nil. A possible way to
26
68
address this is by creating a `UUID` for your objects locally and relying on that for `Equatable` and `Hashable`,
27
69
otherwise it's possible you will get "circular dependency errors" depending on your implementation.
70
+ - note: If you plan to use custom encoding/decoding, be sure to add `objectId`, `createdAt`, `updatedAt`, and
71
+ `ACL` to your `ParseObject` `CodingKeys`.
28
72
*/
29
73
public protocol ParseObject : Objectable ,
30
74
Fetchable ,
0 commit comments