Skip to content

Commit

Permalink
Do not nil out fields if server record returned from conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanashcraft committed Apr 22, 2023
1 parent e113e52 commit 5389fb6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Sources/CloudSyncSession/Middleware/ErrorMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,17 @@ struct ErrorMiddleware: Middleware {
return nil
}

// Always return the server record so we don't end up in a conflict loop.
// The server record has the change tag we want to use.
// https://developer.apple.com/documentation/cloudkit/ckerror/2325208-serverrecordchanged
if serverRecord != resolvedRecord {
// Always return the server record so we don't end up in a conflict loop.
// The server record has the change tag we want to use.
// https://developer.apple.com/documentation/cloudkit/ckerror/2325208-serverrecordchanged

// First, nil out all keys in case any keys in the newly resolved record are nil,
// we don't want those to carry over into the final resolved copy
serverRecord.removeAllFields()
// First, nil out all keys in case any keys in the newly resolved record are nil,
// we don't want those to carry over into the final resolved copy
serverRecord.removeAllFields()

// Copy over all fields from the resolved record
serverRecord.copyFields(from: resolvedRecord)
serverRecord.copyFields(from: resolvedRecord)
}

return serverRecord
}
Expand Down

0 comments on commit 5389fb6

Please sign in to comment.