@@ -25,11 +25,53 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
25
25
self . target = target
26
26
}
27
27
28
+ /**
29
+ An operation that sets a field's value if it has changed from its previous value.
30
+ - Parameters:
31
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
32
+ - value: The value to set it to.
33
+ - returns: The updated operations.
34
+ */
35
+ public func set< W> ( _ key: ( String , WritableKeyPath < T , W > ) ,
36
+ value: W ) throws -> Self where W: Encodable {
37
+ var mutableOperation = self
38
+ guard let target = self . target else {
39
+ throw ParseError ( code: . unknownError, message: " Target shouldn't be nil " )
40
+ }
41
+ if let currentValue = target [ keyPath: key. 1 ] as? NSObject ,
42
+ let updatedValue = value as? NSObject {
43
+ if currentValue != updatedValue {
44
+ mutableOperation. operations [ key. 0 ] = value
45
+ mutableOperation. target ? [ keyPath: key. 1 ] = value
46
+ }
47
+ } else {
48
+ mutableOperation. operations [ key. 0 ] = value
49
+ mutableOperation. target ? [ keyPath: key. 1 ] = value
50
+ }
51
+ return mutableOperation
52
+ }
53
+
54
+ /**
55
+ An operation that force sets a field's value.
56
+ - Parameters:
57
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
58
+ - value: The value to set it to.
59
+ - returns: The updated operations.
60
+ */
61
+ public func forceSet< W> ( _ key: ( String , WritableKeyPath < T , W > ) ,
62
+ value: W ) throws -> Self where W: Encodable {
63
+ var mutableOperation = self
64
+ mutableOperation. operations [ key. 0 ] = value
65
+ mutableOperation. target ? [ keyPath: key. 1 ] = value
66
+ return mutableOperation
67
+ }
68
+
28
69
/**
29
70
An operation that increases a numeric field's value by a given amount.
30
71
- Parameters:
31
72
- key: The key of the object.
32
73
- amount: How much to increment by.
74
+ - returns: The updated operations.
33
75
*/
34
76
public func increment( _ key: String , by amount: Int ) -> Self {
35
77
var mutableOperation = self
@@ -43,6 +85,7 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
43
85
- Parameters:
44
86
- key: The key of the object.
45
87
- objects: The field of objects.
88
+ - returns: The updated operations.
46
89
*/
47
90
public func addUnique< W> ( _ key: String , objects: [ W ] ) -> Self where W: Encodable , W: Hashable {
48
91
var mutableOperation = self
@@ -54,8 +97,9 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
54
97
An operation that adds a new element to an array field,
55
98
only if it wasn't already present.
56
99
- Parameters:
57
- - key: A tuple consisting of the key and KeyPath of the object.
100
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
58
101
- objects: The field of objects.
102
+ - returns: The updated operations.
59
103
*/
60
104
public func addUnique< V> ( _ key: ( String , WritableKeyPath < T , [ V ] > ) ,
61
105
objects: [ V ] ) throws -> Self where V: Encodable , V: Hashable {
@@ -74,8 +118,9 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
74
118
An operation that adds a new element to an array field,
75
119
only if it wasn't already present.
76
120
- Parameters:
77
- - key: A tuple consisting of the key and KeyPath of the object.
121
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
78
122
- objects: The field of objects.
123
+ - returns: The updated operations.
79
124
*/
80
125
public func addUnique< V> ( _ key: ( String , WritableKeyPath < T , [ V ] ? > ) ,
81
126
objects: [ V ] ) throws -> Self where V: Encodable , V: Hashable {
@@ -95,6 +140,7 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
95
140
- Parameters:
96
141
- key: The key of the object.
97
142
- objects: The field of objects.
143
+ - returns: The updated operations.
98
144
*/
99
145
public func add< W> ( _ key: String , objects: [ W ] ) -> Self where W: Encodable {
100
146
var mutableOperation = self
@@ -105,8 +151,9 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
105
151
/**
106
152
An operation that adds a new element to an array field.
107
153
- Parameters:
108
- - key: A tuple consisting of the key and KeyPath of the object.
154
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
109
155
- objects: The field of objects.
156
+ - returns: The updated operations.
110
157
*/
111
158
public func add< V> ( _ key: ( String , WritableKeyPath < T , [ V ] > ) ,
112
159
objects: [ V ] ) throws -> Self where V: Encodable {
@@ -124,8 +171,9 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
124
171
/**
125
172
An operation that adds a new element to an array field.
126
173
- Parameters:
127
- - key: A tuple consisting of the key and KeyPath of the object.
174
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
128
175
- objects: The field of objects.
176
+ - returns: The updated operations.
129
177
*/
130
178
public func add< V> ( _ key: ( String , WritableKeyPath < T , [ V ] ? > ) ,
131
179
objects: [ V ] ) throws -> Self where V: Encodable {
@@ -145,6 +193,7 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
145
193
- Parameters:
146
194
- key: The key of the object.
147
195
- objects: The field of objects.
196
+ - returns: The updated operations.
148
197
*/
149
198
public func addRelation< W> ( _ key: String , objects: [ W ] ) throws -> Self where W: ParseObject {
150
199
var mutableOperation = self
@@ -155,8 +204,9 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
155
204
/**
156
205
An operation that adds a new relation to an array field.
157
206
- Parameters:
158
- - key: A tuple consisting of the key and KeyPath of the object.
207
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
159
208
- objects: The field of objects.
209
+ - returns: The updated operations.
160
210
*/
161
211
public func addRelation< V> ( _ key: ( String , WritableKeyPath < T , [ V ] > ) ,
162
212
objects: [ V ] ) throws -> Self where V: ParseObject {
@@ -174,8 +224,9 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
174
224
/**
175
225
An operation that adds a new relation to an array field.
176
226
- Parameters:
177
- - key: A tuple consisting of the key and KeyPath of the object.
227
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
178
228
- objects: The field of objects.
229
+ - returns: The updated operations.
179
230
*/
180
231
public func addRelation< V> ( _ key: ( String , WritableKeyPath < T , [ V ] ? > ) ,
181
232
objects: [ V ] ) throws -> Self where V: ParseObject {
@@ -196,6 +247,7 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
196
247
- Parameters:
197
248
- key: The key of the object.
198
249
- objects: The field of objects.
250
+ - returns: The updated operations.
199
251
*/
200
252
public func remove< W> ( _ key: String , objects: [ W ] ) -> Self where W: Encodable {
201
253
var mutableOperation = self
@@ -207,8 +259,9 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
207
259
An operation that removes every instance of an element from
208
260
an array field.
209
261
- Parameters:
210
- - key: A tuple consisting of the key and KeyPath of the object.
262
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
211
263
- objects: The field of objects.
264
+ - returns: The updated operations.
212
265
*/
213
266
public func remove< V> ( _ key: ( String , WritableKeyPath < T , [ V ] > ) ,
214
267
objects: [ V ] ) throws -> Self where V: Encodable , V: Hashable {
@@ -230,8 +283,9 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
230
283
An operation that removes every instance of an element from
231
284
an array field.
232
285
- Parameters:
233
- - key: A tuple consisting of the key and KeyPath of the object.
286
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
234
287
- objects: The field of objects.
288
+ - returns: The updated operations.
235
289
*/
236
290
public func remove< V> ( _ key: ( String , WritableKeyPath < T , [ V ] ? > ) ,
237
291
objects: [ V ] ) throws -> Self where V: Encodable , V: Hashable {
@@ -255,6 +309,7 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
255
309
- Parameters:
256
310
- key: The key of the object.
257
311
- objects: The field of objects.
312
+ - returns: The updated operations.
258
313
*/
259
314
public func removeRelation< W> ( _ key: String , objects: [ W ] ) throws -> Self where W: ParseObject {
260
315
var mutableOperation = self
@@ -266,8 +321,9 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
266
321
An operation that removes every instance of a relation from
267
322
an array field.
268
323
- Parameters:
269
- - key: A tuple consisting of the key and KeyPath of the object.
324
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
270
325
- objects: The field of objects.
326
+ - returns: The updated operations.
271
327
*/
272
328
public func removeRelation< V> ( _ key: ( String , WritableKeyPath < T , [ V ] > ) ,
273
329
objects: [ V ] ) throws -> Self where V: ParseObject {
@@ -289,8 +345,9 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
289
345
An operation that removes every instance of a relation from
290
346
an array field.
291
347
- Parameters:
292
- - key: A tuple consisting of the key and KeyPath of the object.
348
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
293
349
- objects: The field of objects.
350
+ - returns: The updated operations.
294
351
*/
295
352
public func removeRelation< V> ( _ key: ( String , WritableKeyPath < T , [ V ] ? > ) ,
296
353
objects: [ V ] ) throws -> Self where V: ParseObject {
@@ -311,6 +368,7 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
311
368
/**
312
369
An operation where a field is deleted from the object.
313
370
- parameter key: The key of the object.
371
+ - returns: The updated operations.
314
372
*/
315
373
public func unset( _ key: String ) -> Self {
316
374
var mutableOperation = self
@@ -321,7 +379,8 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
321
379
/**
322
380
An operation where a field is deleted from the object.
323
381
- Parameters:
324
- - key: A tuple consisting of the key and KeyPath of the object.
382
+ - key: A tuple consisting of the key and the respective KeyPath of the object.
383
+ - returns: The updated operations.
325
384
*/
326
385
public func unset< V> ( _ key: ( String , WritableKeyPath < T , V ? > ) ) -> Self where V: Encodable {
327
386
var mutableOperation = self
0 commit comments