From edd8ba55d8ea6d4b0c921d1e1bcfc5eb8ea53ccc Mon Sep 17 00:00:00 2001 From: John Estropia Date: Sat, 23 Jan 2021 16:51:45 +0900 Subject: [PATCH] fix rare duplication of uniqueID values during import when an import candidate is added by a previous insertion block --- Sources/BaseDataTransaction+Importing.swift | 5 ++++- Sources/DiffableDataSource.TableViewAdapter-UIKit.swift | 2 +- Sources/ImportableUniqueObject.swift | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/BaseDataTransaction+Importing.swift b/Sources/BaseDataTransaction+Importing.swift index 3d6e742..93803d2 100644 --- a/Sources/BaseDataTransaction+Importing.swift +++ b/Sources/BaseDataTransaction+Importing.swift @@ -230,7 +230,10 @@ extension BaseDataTransaction { } try autoreleasepool { - if let object = existingObjectsByID[objectID] { + if let object = existingObjectsByID[objectID] + ?? self.context.insertedObjects + .compactMap({ O.cs_matches(object: $0) ? O.cs_fromRaw(object: $0) : nil }) + .first(where: { $0.uniqueIDValue == objectID }) { guard entityType.shouldUpdate(from: source, in: self) else { diff --git a/Sources/DiffableDataSource.TableViewAdapter-UIKit.swift b/Sources/DiffableDataSource.TableViewAdapter-UIKit.swift index 7e0052b..eb7f8ab 100644 --- a/Sources/DiffableDataSource.TableViewAdapter-UIKit.swift +++ b/Sources/DiffableDataSource.TableViewAdapter-UIKit.swift @@ -63,7 +63,7 @@ extension DiffableDataSource { */ open class TableViewAdapter: BaseAdapter>, UITableViewDataSource { - // MARK: Publi + // MARK: Public /** Initializes the `DiffableDataSource.TableViewAdapter`. This instance needs to be held on (retained) for as long as the `UITableView`'s lifecycle. diff --git a/Sources/ImportableUniqueObject.swift b/Sources/ImportableUniqueObject.swift index 5c4eba0..65924c6 100644 --- a/Sources/ImportableUniqueObject.swift +++ b/Sources/ImportableUniqueObject.swift @@ -53,7 +53,7 @@ import CoreData ) ``` */ -public protocol ImportableUniqueObject: ImportableObject { +public protocol ImportableUniqueObject: ImportableObject, Hashable { /** The data type for the entity's unique ID attribute