diff --git a/DiffableDataSources.xcodeproj/xcshareddata/xcschemes/DiffableDataSources.xcscheme b/DiffableDataSources.xcodeproj/xcshareddata/xcschemes/DiffableDataSources.xcscheme
index afbe573..ed7149a 100644
--- a/DiffableDataSources.xcodeproj/xcshareddata/xcschemes/DiffableDataSources.xcscheme
+++ b/DiffableDataSources.xcodeproj/xcshareddata/xcschemes/DiffableDataSources.xcscheme
@@ -27,6 +27,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
+
+
+
+
@@ -39,17 +48,6 @@
-
-
-
-
-
-
-
-
{
internal var structure = SnapshotStructure()
+ private let forceFallback: Bool
+ private var _nativeSnapshot: Any?
+ @available(iOS 13.0, *)
+ internal var nativeSnapshot: NSDiffableDataSourceSnapshot {
+ get {
+ return _nativeSnapshot as! NSDiffableDataSourceSnapshot
+ }
+ set {
+ _nativeSnapshot = newValue
+ }
+ }
+
/// Creates a new empty snapshot object.
- public init() {}
+ public init() {
+ self.init(forceFallback: false)
+ }
+
+ internal init(forceFallback: Bool) {
+ self.forceFallback = forceFallback
+ if #available(iOS 13.0, *), !forceFallback {
+ nativeSnapshot = .init()
+ return
+ }
+ }
+
+ @available(iOS 13.0, *)
+ static func from(nativeSnapshot: NSDiffableDataSourceSnapshot) -> Self {
+ var snapshot = DiffableDataSourceSnapshot()
+ snapshot.nativeSnapshot = nativeSnapshot
+ return snapshot
+ }
/// The number of item identifiers in the snapshot.
public var numberOfItems: Int {
+ if #available(iOS 13.0, *), !forceFallback {
+ return nativeSnapshot.numberOfItems
+ }
return itemIdentifiers.count
}
/// The number of section identifiers in the snapshot.
public var numberOfSections: Int {
+ if #available(iOS 13.0, *), !forceFallback {
+ return nativeSnapshot.numberOfSections
+ }
return sectionIdentifiers.count
}
/// All section identifiers in the snapshot.
public var sectionIdentifiers: [SectionIdentifierType] {
+ if #available(iOS 13.0, *), !forceFallback {
+ return nativeSnapshot.sectionIdentifiers
+ }
return structure.allSectionIDs
}
/// All item identifiers in the snapshot.
public var itemIdentifiers: [ItemIdentifierType] {
+ if #available(iOS 13.0, *), !forceFallback {
+ return nativeSnapshot.itemIdentifiers
+ }
return structure.allItemIDs
}
@@ -33,6 +76,9 @@ public struct DiffableDataSourceSnapshot Int {
+ if #available(iOS 13.0, *), !forceFallback {
+ return nativeSnapshot.numberOfItems(inSection: identifier)
+ }
return itemIdentifiers(inSection: identifier).count
}
@@ -43,6 +89,9 @@ public struct DiffableDataSourceSnapshot [ItemIdentifierType] {
+ if #available(iOS 13.0, *), !forceFallback {
+ return nativeSnapshot.itemIdentifiers(inSection: identifier)
+ }
return structure.items(in: identifier)
}
@@ -53,6 +102,9 @@ public struct DiffableDataSourceSnapshot SectionIdentifierType? {
+ if #available(iOS 13.0, *), !forceFallback {
+ return nativeSnapshot.sectionIdentifier(containingItem: identifier)
+ }
return structure.section(containing: identifier)
}
@@ -63,6 +115,9 @@ public struct DiffableDataSourceSnapshot Int? {
+ if #available(iOS 13.0, *), !forceFallback {
+ return nativeSnapshot.indexOfItem(identifier)
+ }
return itemIdentifiers.firstIndex { $0.isEqualHash(to: identifier) }
}
@@ -73,6 +128,9 @@ public struct DiffableDataSourceSnapshot Int? {
+ if #available(iOS 13.0, *), !forceFallback {
+ return nativeSnapshot.indexOfSection(identifier)
+ }
return sectionIdentifiers.firstIndex { $0.isEqualHash(to: identifier) }
}
@@ -82,6 +140,9 @@ public struct DiffableDataSourceSnapshot DiffableDataSourceSnapshot {
- var snapshot = DiffableDataSourceSnapshot()
+ func snapshot(forceFallback: Bool) -> DiffableDataSourceSnapshot {
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: forceFallback)
snapshot.structure.sections = currentSnapshot.structure.sections
return snapshot
}
diff --git a/Sources/UIKit/CollectionViewDiffableDataSource.swift b/Sources/UIKit/CollectionViewDiffableDataSource.swift
index 8c13d99..43c47eb 100644
--- a/Sources/UIKit/CollectionViewDiffableDataSource.swift
+++ b/Sources/UIKit/CollectionViewDiffableDataSource.swift
@@ -19,17 +19,45 @@ open class CollectionViewDiffableDataSource()
+ private let forceFallback: Bool
+ private var _nativeDataSource: Any?
+ @available(iOS 13.0, *)
+ private var nativeDataSource: UICollectionViewDiffableDataSource {
+ get {
+ guard let nativeDataSource = _nativeDataSource as? UICollectionViewDiffableDataSource else {
+ fatalError()
+ }
+ return nativeDataSource
+ }
+ set {
+ _nativeDataSource = newValue
+ }
+ }
+
+ @available(iOS 13.0, *)
+ private func createNativeDataSource(for collectionView: UICollectionView, cellProvider: @escaping CellProvider) {
+ _nativeDataSource = UICollectionViewDiffableDataSource(collectionView: collectionView, cellProvider: cellProvider)
+ }
/// Creates a new data source.
///
/// - Parameters:
/// - collectionView: A collection view instance to be managed.
/// - cellProvider: A closure to dequeue the cell for items.
- public init(collectionView: UICollectionView, cellProvider: @escaping CellProvider) {
+ public convenience init(collectionView: UICollectionView, cellProvider: @escaping CellProvider) {
+ self.init(collectionView: collectionView, forceFallback: false, cellProvider: cellProvider)
+ }
+
+ internal init(collectionView: UICollectionView, forceFallback: Bool, cellProvider: @escaping CellProvider) {
self.collectionView = collectionView
self.cellProvider = cellProvider
+ self.forceFallback = forceFallback
super.init()
+ if #available(iOS 13, *), !forceFallback {
+ createNativeDataSource(for: collectionView, cellProvider: cellProvider)
+ return
+ }
collectionView.dataSource = self
}
@@ -42,13 +70,17 @@ open class CollectionViewDiffableDataSource, animatingDifferences: Bool = true, completion: (() -> Void)? = nil) {
+ if #available(iOS 13, *), !forceFallback {
+ nativeDataSource.apply(snapshot.nativeSnapshot, animatingDifferences: animatingDifferences, completion: completion)
+ return
+ }
core.apply(
snapshot,
view: collectionView,
animatingDifferences: animatingDifferences,
performUpdates: { collectionView, changeset, setSections in
collectionView.reload(using: changeset, setData: setSections)
- },
+ },
completion: completion
)
}
@@ -57,7 +89,10 @@ open class CollectionViewDiffableDataSource DiffableDataSourceSnapshot {
- return core.snapshot()
+ if #available(iOS 13, *), !forceFallback {
+ return .from(nativeSnapshot: nativeDataSource.snapshot())
+ }
+ return core.snapshot(forceFallback: forceFallback)
}
/// Returns an item identifier for given index path.
@@ -67,6 +102,9 @@ open class CollectionViewDiffableDataSource ItemIdentifierType? {
+ if #available(iOS 13, *), !forceFallback {
+ return nativeDataSource.itemIdentifier(for: indexPath)
+ }
return core.itemIdentifier(for: indexPath)
}
@@ -77,6 +115,9 @@ open class CollectionViewDiffableDataSource IndexPath? {
+ if #available(iOS 13, *), !forceFallback {
+ return nativeDataSource.indexPath(for: itemIdentifier)
+ }
return core.indexPath(for: itemIdentifier)
}
@@ -87,6 +128,9 @@ open class CollectionViewDiffableDataSource Int {
+ if #available(iOS 13, *), !forceFallback {
+ return nativeDataSource.numberOfSections(in: collectionView)
+ }
return core.numberOfSections()
}
@@ -98,6 +142,9 @@ open class CollectionViewDiffableDataSource Int {
+ if #available(iOS 13, *), !forceFallback {
+ return nativeDataSource.collectionView(collectionView, numberOfItemsInSection: section)
+ }
return core.numberOfItems(inSection: section)
}
@@ -109,6 +156,9 @@ open class CollectionViewDiffableDataSource UICollectionViewCell {
+ if #available(iOS 13, *), !forceFallback {
+ return nativeDataSource.collectionView(collectionView, cellForItemAt: indexPath)
+ }
let itemIdentifier = core.unsafeItemIdentifier(for: indexPath)
guard let cell = cellProvider(collectionView, indexPath, itemIdentifier) else {
universalError("UICollectionView dataSource returned a nil cell for item at index path: \(indexPath), collectionView: \(collectionView), itemIdentifier: \(itemIdentifier)")
@@ -126,6 +176,9 @@ open class CollectionViewDiffableDataSource UICollectionReusableView {
+ if #available(iOS 13, *), !forceFallback {
+ return nativeDataSource.collectionView(collectionView, viewForSupplementaryElementOfKind: kind, at: indexPath)
+ }
guard let view = supplementaryViewProvider?(collectionView, kind, indexPath) else {
return UICollectionReusableView()
}
diff --git a/Sources/UIKit/TableViewDiffableDataSource.swift b/Sources/UIKit/TableViewDiffableDataSource.swift
index 0bb1f2e..ad28ad6 100644
--- a/Sources/UIKit/TableViewDiffableDataSource.swift
+++ b/Sources/UIKit/TableViewDiffableDataSource.swift
@@ -16,17 +16,45 @@ open class TableViewDiffableDataSource()
+ private let forceFallback: Bool
+ private var _nativeDataSource: Any?
+ @available(iOS 13.0, *)
+ private var nativeDataSource: UITableViewDiffableDataSource {
+ get {
+ guard let nativeDataSource = _nativeDataSource as? UITableViewDiffableDataSource else {
+ fatalError()
+ }
+ return nativeDataSource
+ }
+ set {
+ _nativeDataSource = newValue
+ }
+ }
+
+ @available(iOS 13.0, *)
+ private func createNativeDataSource(for tableView: UITableView, cellProvider: @escaping CellProvider) {
+ _nativeDataSource = UITableViewDiffableDataSource(tableView: tableView, cellProvider: cellProvider)
+ }
/// Creates a new data source.
///
/// - Parameters:
/// - tableView: A table view instance to be managed.
/// - cellProvider: A closure to dequeue the cell for rows.
- public init(tableView: UITableView, cellProvider: @escaping CellProvider) {
+ public convenience init(tableView: UITableView, cellProvider: @escaping CellProvider) {
+ self.init(tableView: tableView, forceFallback: false, cellProvider: cellProvider)
+ }
+
+ internal init(tableView: UITableView, forceFallback: Bool, cellProvider: @escaping CellProvider) {
self.tableView = tableView
self.cellProvider = cellProvider
+ self.forceFallback = forceFallback
super.init()
+ if #available(iOS 13, *), !forceFallback {
+ createNativeDataSource(for: tableView, cellProvider: cellProvider)
+ return
+ }
tableView.dataSource = self
}
@@ -39,13 +67,17 @@ open class TableViewDiffableDataSource, animatingDifferences: Bool = true, completion: (() -> Void)? = nil) {
+ if #available(iOS 13, *), !forceFallback {
+ nativeDataSource.apply(snapshot.nativeSnapshot, animatingDifferences: animatingDifferences, completion: completion)
+ return
+ }
core.apply(
snapshot,
view: tableView,
animatingDifferences: animatingDifferences,
performUpdates: { tableView, changeset, setSections in
tableView.reload(using: changeset, with: self.defaultRowAnimation, setData: setSections)
- },
+ },
completion: completion
)
}
@@ -54,7 +86,10 @@ open class TableViewDiffableDataSource DiffableDataSourceSnapshot {
- return core.snapshot()
+ if #available(iOS 13, *), !forceFallback {
+ return .from(nativeSnapshot: nativeDataSource.snapshot())
+ }
+ return core.snapshot(forceFallback: forceFallback)
}
/// Returns an item identifier for given index path.
@@ -64,6 +99,9 @@ open class TableViewDiffableDataSource ItemIdentifierType? {
+ if #available(iOS 13, *), !forceFallback {
+ return nativeDataSource.itemIdentifier(for: indexPath)
+ }
return core.itemIdentifier(for: indexPath)
}
@@ -74,6 +112,9 @@ open class TableViewDiffableDataSource IndexPath? {
+ if #available(iOS 13, *), !forceFallback {
+ return nativeDataSource.indexPath(for: itemIdentifier)
+ }
return core.indexPath(for: itemIdentifier)
}
@@ -84,6 +125,9 @@ open class TableViewDiffableDataSource Int {
+ if #available(iOS 13, *), !forceFallback {
+ return nativeDataSource.numberOfSections(in: tableView)
+ }
return core.numberOfSections()
}
@@ -95,6 +139,9 @@ open class TableViewDiffableDataSource Int {
+ if #available(iOS 13, *), !forceFallback {
+ return nativeDataSource.tableView(tableView, numberOfRowsInSection: section)
+ }
return core.numberOfItems(inSection: section)
}
@@ -128,6 +175,9 @@ open class TableViewDiffableDataSource UITableViewCell {
+ if #available(iOS 13, *), !forceFallback {
+ return nativeDataSource.tableView(tableView, cellForRowAt: indexPath)
+ }
let itemIdentifier = core.unsafeItemIdentifier(for: indexPath)
guard let cell = cellProvider(tableView, indexPath, itemIdentifier) else {
universalError("UITableView dataSource returned a nil cell for row at index path: \(indexPath), tableView: \(tableView), itemIdentifier: \(itemIdentifier)")
@@ -143,7 +193,7 @@ open class TableViewDiffableDataSource Bool {
+ open func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return false
}
@@ -154,7 +204,7 @@ open class TableViewDiffableDataSource Bool {
+ open func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
return false
}
diff --git a/Tests/CollectionViewDiffableDataSourceTests.swift b/Tests/CollectionViewDiffableDataSourceTests.swift
index 212eff5..bcc7450 100644
--- a/Tests/CollectionViewDiffableDataSourceTests.swift
+++ b/Tests/CollectionViewDiffableDataSourceTests.swift
@@ -7,7 +7,7 @@ import UIKit
final class CollectionViewDiffableDataSourceTests: XCTestCase {
func testInit() {
let collectionView = MockCollectionView()
- let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView) { _, _, _ in
+ let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView, forceFallback: true) { _, _, _ in
UICollectionViewCell()
}
@@ -16,11 +16,11 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase {
func testApply() {
let collectionView = MockCollectionView()
- let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView) { _, _, _ in
+ let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView, forceFallback: true) { _, _, _ in
UICollectionViewCell()
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
let e1 = expectation(description: "testApply() e1")
dataSource.apply(snapshot, completion: e1.fulfill)
@@ -50,7 +50,7 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase {
func testSnapshot() {
let collectionView = MockCollectionView()
- let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView) { _, _, _ in
+ let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView, forceFallback: true) { _, _, _ in
UICollectionViewCell()
}
@@ -65,7 +65,7 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase {
XCTAssertEqual(snapshot3.sectionIdentifiers, [])
XCTAssertEqual(snapshot3.itemIdentifiers, [])
- var snapshotToApply = DiffableDataSourceSnapshot()
+ var snapshotToApply = DiffableDataSourceSnapshot(forceFallback: true)
snapshotToApply.appendSections([0, 1, 2])
snapshotToApply.appendItems([0, 1, 2])
dataSource.apply(snapshotToApply)
@@ -92,11 +92,11 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase {
func testItemIdentifier() {
let collectionView = MockCollectionView()
- let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView) { _, _, _ in
+ let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView, forceFallback: true) { _, _, _ in
UICollectionViewCell()
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)
@@ -107,11 +107,11 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase {
func testIndexPath() {
let collectionView = MockCollectionView()
- let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView) { _, _, _ in
+ let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView, forceFallback: true) { _, _, _ in
UICollectionViewCell()
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)
@@ -122,13 +122,13 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase {
func testNumberOfSections() {
let collectionView = MockCollectionView()
- let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView) { _, _, _ in
+ let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView, forceFallback: true) { _, _, _ in
UICollectionViewCell()
}
XCTAssertEqual(dataSource.numberOfSections(in: collectionView), 0)
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)
@@ -138,11 +138,11 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase {
func testNumberOfRowsInSection() {
let collectionView = MockCollectionView()
- let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView) { _, _, _ in
+ let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView, forceFallback: true) { _, _, _ in
UICollectionViewCell()
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)
@@ -153,11 +153,11 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase {
func testCellForRowAt() {
let collectionView = MockCollectionView()
let cell = UICollectionViewCell()
- let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView) { _, _, _ in
+ let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView, forceFallback: true) { _, _, _ in
cell
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)
@@ -171,11 +171,11 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase {
func testCanMoveRowAt() {
let collectionView = MockCollectionView()
let cell = UICollectionViewCell()
- let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView) { _, _, _ in
+ let dataSource = CollectionViewDiffableDataSource(collectionView: collectionView, forceFallback: true) { _, _, _ in
cell
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)
diff --git a/Tests/DiffableDataSourceTests.swift b/Tests/DiffableDataSourceTests.swift
index 7adf171..368dc01 100644
--- a/Tests/DiffableDataSourceTests.swift
+++ b/Tests/DiffableDataSourceTests.swift
@@ -16,7 +16,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
snapshot.appendSections(test.append)
XCTAssertEqual(snapshot.sectionIdentifiers, test.expected)
@@ -33,7 +33,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
snapshot.appendSections(test.append)
XCTAssertEqual(snapshot.sectionIdentifiers, test.expected)
@@ -51,7 +51,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
snapshot.insertSections(test.insert, beforeSection: test.before)
XCTAssertEqual(snapshot.sectionIdentifiers, test.expected)
@@ -67,7 +67,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
snapshot.insertSections(test.insert, beforeSection: test.before)
XCTAssertEqual(snapshot.sectionIdentifiers, test.expected)
@@ -86,7 +86,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
snapshot.insertSections(test.insert, afterSection: test.after)
XCTAssertEqual(snapshot.sectionIdentifiers, test.expected)
@@ -102,7 +102,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
snapshot.insertSections(test.insert, afterSection: test.after)
XCTAssertEqual(snapshot.sectionIdentifiers, test.expected)
@@ -122,7 +122,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
snapshot.deleteSections(test.delete)
XCTAssertEqual(snapshot.sectionIdentifiers, test.expected)
@@ -140,7 +140,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
snapshot.moveSection(test.move, beforeSection: test.before)
XCTAssertEqual(snapshot.sectionIdentifiers, test.expected)
@@ -158,7 +158,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
snapshot.moveSection(test.move, afterSection: test.after)
XCTAssertEqual(snapshot.sectionIdentifiers, test.expected)
@@ -194,7 +194,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
snapshot.reloadSections(test.reload)
XCTAssertEqual(snapshot.sectionIdentifiers, test.initial)
@@ -213,7 +213,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1])
snapshot.appendItems(test.initial)
snapshot.appendItems(test.append)
@@ -231,7 +231,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1])
snapshot.appendItems(test.initial)
snapshot.appendItems(test.append)
@@ -253,7 +253,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items)
@@ -276,7 +276,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items)
@@ -302,7 +302,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1])
snapshot.appendItems(test.initial)
snapshot.insertItems(test.insert, beforeItem: test.before)
@@ -320,7 +320,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1])
snapshot.appendItems(test.initial)
snapshot.insertItems(test.insert, beforeItem: test.before)
@@ -341,7 +341,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1])
snapshot.appendItems(test.initial)
snapshot.insertItems(test.insert, afterItem: test.after)
@@ -359,7 +359,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1])
snapshot.appendItems(test.initial)
snapshot.insertItems(test.insert, afterItem: test.after)
@@ -382,7 +382,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -409,7 +409,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -435,7 +435,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -463,7 +463,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -539,7 +539,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -564,7 +564,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -583,7 +583,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -602,7 +602,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
XCTAssertEqual(snapshot.numberOfSections, test.expected)
@@ -618,7 +618,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
XCTAssertEqual(snapshot.numberOfSections, test.expected)
@@ -636,7 +636,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -655,7 +655,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -674,7 +674,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
XCTAssertEqual(snapshot.sectionIdentifiers, test.expected)
@@ -690,7 +690,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
XCTAssertEqual(snapshot.sectionIdentifiers, test.expected)
@@ -708,7 +708,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -727,7 +727,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -748,7 +748,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -767,7 +767,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -789,7 +789,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -808,7 +808,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -830,7 +830,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -849,7 +849,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
for (section, items) in test.initial.enumerated() {
snapshot.appendSections([section])
snapshot.appendItems(items, toSection: section)
@@ -870,7 +870,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
XCTAssertEqual(snapshot.indexOfSection(test.section), test.expectedIndex)
@@ -886,7 +886,7 @@ final class DiffableDataSourceSnapshotTests: XCTestCase {
]
for test in tests {
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections(test.initial)
XCTAssertEqual(snapshot.indexOfSection(test.section), test.expectedIndex)
diff --git a/Tests/TableViewDiffableDataSourceTests.swift b/Tests/TableViewDiffableDataSourceTests.swift
index 8cec845..a6e2c66 100644
--- a/Tests/TableViewDiffableDataSourceTests.swift
+++ b/Tests/TableViewDiffableDataSourceTests.swift
@@ -7,7 +7,7 @@ import UIKit
final class TableViewDiffableDataSourceTests: XCTestCase {
func testInit() {
let tableView = MockTableView()
- let dataSource = TableViewDiffableDataSource(tableView: tableView) { _, _, _ in
+ let dataSource = TableViewDiffableDataSource(tableView: tableView, forceFallback: true) { _, _, _ in
UITableViewCell()
}
@@ -16,11 +16,11 @@ final class TableViewDiffableDataSourceTests: XCTestCase {
func testApply() {
let tableView = MockTableView()
- let dataSource = TableViewDiffableDataSource(tableView: tableView) { _, _, _ in
+ let dataSource = TableViewDiffableDataSource(tableView: tableView, forceFallback: true) { _, _, _ in
UITableViewCell()
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
let e1 = expectation(description: "testApply() e1")
dataSource.apply(snapshot, completion: e1.fulfill)
@@ -50,7 +50,7 @@ final class TableViewDiffableDataSourceTests: XCTestCase {
func testSnapshot() {
let tableView = MockTableView()
- let dataSource = TableViewDiffableDataSource(tableView: tableView) { _, _, _ in
+ let dataSource = TableViewDiffableDataSource(tableView: tableView, forceFallback: true) { _, _, _ in
UITableViewCell()
}
@@ -65,7 +65,7 @@ final class TableViewDiffableDataSourceTests: XCTestCase {
XCTAssertEqual(snapshot3.sectionIdentifiers, [])
XCTAssertEqual(snapshot3.itemIdentifiers, [])
- var snapshotToApply = DiffableDataSourceSnapshot()
+ var snapshotToApply = DiffableDataSourceSnapshot(forceFallback: true)
snapshotToApply.appendSections([0, 1, 2])
snapshotToApply.appendItems([0, 1, 2])
dataSource.apply(snapshotToApply)
@@ -92,11 +92,11 @@ final class TableViewDiffableDataSourceTests: XCTestCase {
func testItemIdentifier() {
let tableView = MockTableView()
- let dataSource = TableViewDiffableDataSource(tableView: tableView) { _, _, _ in
+ let dataSource = TableViewDiffableDataSource(tableView: tableView, forceFallback: true) { _, _, _ in
UITableViewCell()
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)
@@ -107,11 +107,11 @@ final class TableViewDiffableDataSourceTests: XCTestCase {
func testIndexPath() {
let tableView = MockTableView()
- let dataSource = TableViewDiffableDataSource(tableView: tableView) { _, _, _ in
+ let dataSource = TableViewDiffableDataSource(tableView: tableView, forceFallback: true) { _, _, _ in
UITableViewCell()
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)
@@ -122,13 +122,13 @@ final class TableViewDiffableDataSourceTests: XCTestCase {
func testNumberOfSections() {
let tableView = MockTableView()
- let dataSource = TableViewDiffableDataSource(tableView: tableView) { _, _, _ in
+ let dataSource = TableViewDiffableDataSource(tableView: tableView, forceFallback: true) { _, _, _ in
UITableViewCell()
}
XCTAssertEqual(dataSource.numberOfSections(in: tableView), 0)
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)
@@ -138,11 +138,11 @@ final class TableViewDiffableDataSourceTests: XCTestCase {
func testNumberOfRowsInSection() {
let tableView = MockTableView()
- let dataSource = TableViewDiffableDataSource(tableView: tableView) { _, _, _ in
+ let dataSource = TableViewDiffableDataSource(tableView: tableView, forceFallback: true) { _, _, _ in
UITableViewCell()
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)
@@ -153,11 +153,11 @@ final class TableViewDiffableDataSourceTests: XCTestCase {
func testCellForRowAt() {
let tableView = MockTableView()
let cell = UITableViewCell()
- let dataSource = TableViewDiffableDataSource(tableView: tableView) { _, _, _ in
+ let dataSource = TableViewDiffableDataSource(tableView: tableView, forceFallback: true) { _, _, _ in
cell
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)
@@ -171,11 +171,11 @@ final class TableViewDiffableDataSourceTests: XCTestCase {
func testCanEditRowAt() {
let tableView = MockTableView()
let cell = UITableViewCell()
- let dataSource = TableViewDiffableDataSource(tableView: tableView) { _, _, _ in
+ let dataSource = TableViewDiffableDataSource(tableView: tableView, forceFallback: true) { _, _, _ in
cell
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)
@@ -189,11 +189,11 @@ final class TableViewDiffableDataSourceTests: XCTestCase {
func testCanMoveRowAt() {
let tableView = MockTableView()
let cell = UITableViewCell()
- let dataSource = TableViewDiffableDataSource(tableView: tableView) { _, _, _ in
+ let dataSource = TableViewDiffableDataSource(tableView: tableView, forceFallback: true) { _, _, _ in
cell
}
- var snapshot = DiffableDataSourceSnapshot()
+ var snapshot = DiffableDataSourceSnapshot(forceFallback: true)
snapshot.appendSections([0, 1, 2])
snapshot.appendItems([0, 1, 2], toSection: 0)
dataSource.apply(snapshot)