diff --git a/Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift b/Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift index aa5eb7e..2d837d5 100644 --- a/Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift +++ b/Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift @@ -35,7 +35,7 @@ open class CocoaCollectionViewDiffableDataSource, animatingDifferences: Bool = true) { + public func apply(_ snapshot: DiffableDataSourceSnapshot, animatingDifferences: Bool = true, completion: (() -> Void)? = nil) { core.apply( snapshot, view: collectionView, diff --git a/Tests/CocoaCollectionViewDiffableDataSourceTests.swift b/Tests/CocoaCollectionViewDiffableDataSourceTests.swift index ca54824..c500e01 100644 --- a/Tests/CocoaCollectionViewDiffableDataSourceTests.swift +++ b/Tests/CocoaCollectionViewDiffableDataSourceTests.swift @@ -22,21 +22,29 @@ final class CocoaCollectionViewDiffableDataSourceTests: XCTestCase { var snapshot = DiffableDataSourceSnapshot() - dataSource.apply(snapshot) + let e1 = expectation(description: "testApply() e1") + dataSource.apply(snapshot, completion: e1.fulfill) + wait(for: [e1], timeout: 1) XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 0) snapshot.appendSections([0]) snapshot.appendItems([0]) - dataSource.apply(snapshot) + let e2 = expectation(description: "testApply() e2") + dataSource.apply(snapshot, completion: e2.fulfill) + wait(for: [e2], timeout: 1) XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1) - dataSource.apply(snapshot) + let e3 = expectation(description: "testApply() e3") + dataSource.apply(snapshot, completion: e3.fulfill) + wait(for: [e3], timeout: 1) XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1) snapshot.appendItems([1]) - dataSource.apply(snapshot) + let e4 = expectation(description: "testApply() e4") + dataSource.apply(snapshot, completion: e4.fulfill) + wait(for: [e4], timeout: 1) XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 2) } diff --git a/Tests/CollectionViewDiffableDataSourceTests.swift b/Tests/CollectionViewDiffableDataSourceTests.swift index e419a54..872683a 100644 --- a/Tests/CollectionViewDiffableDataSourceTests.swift +++ b/Tests/CollectionViewDiffableDataSourceTests.swift @@ -22,21 +22,29 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase { var snapshot = DiffableDataSourceSnapshot() - dataSource.apply(snapshot) + let e1 = expectation(description: "testApply() e1") + dataSource.apply(snapshot, completion: e1.fulfill) + wait(for: [e1], timeout: 1) XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 0) snapshot.appendSections([0]) snapshot.appendItems([0]) - dataSource.apply(snapshot) + let e2 = expectation(description: "testApply() e2") + dataSource.apply(snapshot, completion: e2.fulfill) + wait(for: [e2], timeout: 1) XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1) - dataSource.apply(snapshot) + let e3 = expectation(description: "testApply() e3") + dataSource.apply(snapshot, completion: e3.fulfill) + wait(for: [e3], timeout: 1) XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1) snapshot.appendItems([1]) - dataSource.apply(snapshot) + let e4 = expectation(description: "testApply() e4") + dataSource.apply(snapshot, completion: e4.fulfill) + wait(for: [e4], timeout: 1) XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 2) } diff --git a/Tests/TableViewDiffableDataSourceTests.swift b/Tests/TableViewDiffableDataSourceTests.swift index c29cd3f..ce3e1cb 100644 --- a/Tests/TableViewDiffableDataSourceTests.swift +++ b/Tests/TableViewDiffableDataSourceTests.swift @@ -22,21 +22,29 @@ final class TableViewDiffableDataSourceTests: XCTestCase { var snapshot = DiffableDataSourceSnapshot() - dataSource.apply(snapshot) + let e1 = expectation(description: "testApply() e1") + dataSource.apply(snapshot, completion: e1.fulfill) + wait(for: [e1], timeout: 1) XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 0) snapshot.appendSections([0]) snapshot.appendItems([0]) - dataSource.apply(snapshot) + let e2 = expectation(description: "testApply() e2") + dataSource.apply(snapshot, completion: e2.fulfill) + wait(for: [e2], timeout: 1) XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 1) - dataSource.apply(snapshot) + let e3 = expectation(description: "testApply() e3") + dataSource.apply(snapshot, completion: e3.fulfill) + wait(for: [e3], timeout: 1) XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 1) snapshot.appendItems([1]) - dataSource.apply(snapshot) + let e4 = expectation(description: "testApply() e4") + dataSource.apply(snapshot, completion: e4.fulfill) + wait(for: [e4], timeout: 1) XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 2) }