feat: add set operation based on KeyPath #403
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New Pull Request Checklist
Issue Description
Using the set
ParseOperation
The
set
operation currently requires using a tuple of thekey
String andKeyPath
. This redundancy is because currently there is no way to get the string value of aKeyPath
reliably without the developer supplying the correctkey
String. Errors can be reduced when using theset
operation if only theKeyPath
is used to set the value instead of thekey
String.Unwrapping optional
ParseObject
propertiesSafely unwrapping properties in Swift is easy, but can be cumbersome and require extra code. Since all properties of a
ParseObject
are required to be optional for encoding/decoding andParse Pointer
purposes developers usually have to write additional code to unwrap values. It would be nice if a helper method was provided that can do this.Related issue: #n/a
Approach
Using the set
ParseOperation
Since the
ParseOperation
has theParseObject
as a target, add aset
operation method that only needs theKeyPath
and the value to set. This only works forset
as the rest of the operations require additional information modified on the target and sent to the server to complete the operation. In addition, it doesn't work for setting nil values as this requires the SDK to encode aNSNull
value instead ofnil
.Usage of the new set method can only be used when using multiple calls of the same method (different
KeyPath
). The SDK will throw an error if the developer attempts to combine other types of operations such as:add
,increment
,forceSet
, etc. This is because the other operations methods work entirely different than the new method. The new method sets changes directly on the target and uses the targets save/update methods as opposed to the others which save operations into a dictionary to encode to the server.Unwrapping optional
ParseObject
propertiesAdds the
get() throws
method to allow developers to get the unwrapped property of any ParseObject based on its KeyPath. This will save developers the hassle of having to write code to safely unwrap properties of aParseObject
. If the property is nil, an error will be thrown. Usage:TODOs before merging