Skip to content

Commit ec71155

Browse files
committed
update documentation and tests
1 parent 434dd8e commit ec71155

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

Sources/ParseSwift/Objects/ParseObject.swift

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public extension ParseObject {
161161
}
162162

163163
var mergeable: Self {
164-
guard objectId != nil,
164+
guard isSaved,
165165
originalData == nil else {
166166
return self
167167
}
@@ -318,13 +318,11 @@ public extension ParseObject {
318318
a Parse Server. You can also use this method on a new `ParseObject`'s that has not been saved to a Parse Server
319319
as long as the `objectId` of the respective `ParseObject` is **nil**.
320320
- attention: If you are using the `set()` method, you do not need to implement `merge()`. Using `set()`
321-
may perform slower than implemting `merge()` after saving the updated `ParseObject` to a Parse Server.
322-
This is due to extra overhead in encoding/decoding the object inorder to determine what keys have been updated.
323-
Developers should choose what option works best for their respective applications.
321+
may perform slower than implementing `merge()` after saving the updated `ParseObject` to a Parse Server.
322+
This is due to neccesary overhead required to determine what keys have been updated. If a developer finds decoding
323+
updated `ParseObjects`'s to be slow, implementing `merge()` may speed up the process.
324324
- warning: This method should always be used when making the very first update/mutation to your `ParseObject`.
325-
Any subsequent mutations can modify the `ParseObject` property directly or by making mutiple `set()` calls.
326-
- warning: If you have add properties to your `ParseObject`that are of type `Date` and need the precise time of
327-
the date, you should implement `merge()` or call `fetch()` on your object after updating.
325+
Any subsequent mutations can modify the `ParseObject` property directly or use the `set()` method.
328326
*/
329327
func set<W>(_ keyPath: WritableKeyPath<Self, W?>, to value: W) -> Self where W: Equatable {
330328
var updated = self.mergeable
@@ -348,11 +346,8 @@ extension ParseObject {
348346
original[key] = value
349347
}
350348
let mergedEncoded = try JSONSerialization.data(withJSONObject: original)
351-
var merged = try ParseCoding.jsonDecoder().decode(Self.self,
352-
from: mergedEncoded)
353-
merged.createdAt = originalObject.createdAt
354-
merged.updatedAt = updatedAt
355-
return merged
349+
return try ParseCoding.jsonDecoder().decode(Self.self,
350+
from: mergedEncoded)
356351
}
357352
}
358353

Tests/ParseSwiftTests/ParseInstallationTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ class ParseInstallationTests: XCTestCase { // swiftlint:disable:this type_body_l
380380
original.customKey = updated.customKey
381381
var merged = try updated.merge(with: original)
382382
merged.originalData = nil
383+
// Get dates in correct format from ParseDecoding strategy
384+
let encoded = try ParseCoding.jsonEncoder().encode(original)
385+
original = try ParseCoding.jsonDecoder().decode(InstallationDefaultMerge.self, from: encoded)
383386
XCTAssertEqual(merged, original)
384387
}
385388

@@ -406,7 +409,7 @@ class ParseInstallationTests: XCTestCase { // swiftlint:disable:this type_body_l
406409
let encoded: Data!
407410
do {
408411
encoded = try installationOnServer.getEncoder().encode(installationOnServer, skipKeys: .none)
409-
//Get dates in correct format from ParseDecoding strategy
412+
// Get dates in correct format from ParseDecoding strategy
410413
installationOnServer = try installationOnServer.getDecoder().decode(Installation.self, from: encoded)
411414
} catch {
412415
XCTFail("Should encode/decode. Error \(error)")

Tests/ParseSwiftTests/ParseObjectTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ class ParseObjectTests: XCTestCase { // swiftlint:disable:this type_body_length
434434
score.name = updated.name
435435
var merged = try updated.merge(with: score)
436436
merged.originalData = nil
437+
// Get dates in correct format from ParseDecoding strategy
438+
let encoded = try ParseCoding.jsonEncoder().encode(score)
439+
score = try ParseCoding.jsonDecoder().decode(GameDefaultMerge.self, from: encoded)
437440
XCTAssertEqual(merged, score)
438441
}
439442

Tests/ParseSwiftTests/ParseUserTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ class ParseUserTests: XCTestCase { // swiftlint:disable:this type_body_length
222222
original.updatedAt = updated.updatedAt
223223
var merged = try updated.merge(with: original)
224224
merged.originalData = nil
225+
// Get dates in correct format from ParseDecoding strategy
226+
let encoded = try ParseCoding.jsonEncoder().encode(original)
227+
original = try ParseCoding.jsonDecoder().decode(UserDefaultMerge.self, from: encoded)
225228
XCTAssertEqual(merged, original)
226229
}
227230

0 commit comments

Comments
 (0)