From 6b7c1a25979611b9cc12e17b8fe196ae8d5101e3 Mon Sep 17 00:00:00 2001 From: Anna Lutsenko Date: Thu, 19 Jan 2023 17:11:29 +0100 Subject: [PATCH] Implemented SPM support --- .../contents.xcworkspacedata | 7 ++++ Package.resolved | 41 +++++++++++++++++++ Package.swift | 33 +++++++++++++++ {sources => Sources/Delta}/cache.swift | 0 .../data_structures/collection_record.swift | 0 .../Delta}/data_structures/delta_change.swift | 0 .../Delta}/data_structures/delta_item.swift | 0 .../data_structures/delta_section.swift | 0 {sources => Sources/Delta}/delta.swift | 2 +- .../extensions/UICollectionViewDelta.swift | 4 +- .../Delta}/extensions/UITableViewDelta.swift | 4 +- {sources => Sources/Delta}/processor.swift | 4 +- {tests => Tests/DeltaTests}/delta_spec.swift | 2 +- .../DeltaTests}/processor_spec.swift | 0 14 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata create mode 100644 Package.resolved create mode 100644 Package.swift rename {sources => Sources/Delta}/cache.swift (100%) rename {sources => Sources/Delta}/data_structures/collection_record.swift (100%) rename {sources => Sources/Delta}/data_structures/delta_change.swift (100%) rename {sources => Sources/Delta}/data_structures/delta_item.swift (100%) rename {sources => Sources/Delta}/data_structures/delta_section.swift (100%) rename {sources => Sources/Delta}/delta.swift (99%) rename {sources => Sources/Delta}/extensions/UICollectionViewDelta.swift (90%) rename {sources => Sources/Delta}/extensions/UITableViewDelta.swift (93%) rename {sources => Sources/Delta}/processor.swift (94%) rename {tests => Tests/DeltaTests}/delta_spec.swift (99%) rename {tests => Tests/DeltaTests}/processor_spec.swift (100%) diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..dc8d94e --- /dev/null +++ b/Package.resolved @@ -0,0 +1,41 @@ +{ + "pins" : [ + { + "identity" : "cwlcatchexception", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mattgallagher/CwlCatchException.git", + "state" : { + "revision" : "35f9e770f54ce62dd8526470f14c6e137cef3eea", + "version" : "2.1.1" + } + }, + { + "identity" : "cwlpreconditiontesting", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git", + "state" : { + "revision" : "c21f7bab5ca8eee0a9998bbd17ca1d0eb45d4688", + "version" : "2.1.0" + } + }, + { + "identity" : "nimble", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Quick/Nimble", + "state" : { + "revision" : "1f3bde57bde12f5e7b07909848c071e9b73d6edc", + "version" : "10.0.0" + } + }, + { + "identity" : "quick", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Quick/Quick", + "state" : { + "revision" : "f9d519828bb03dfc8125467d8f7b93131951124c", + "version" : "5.0.1" + } + } + ], + "version" : 2 +} diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..dcb75cc --- /dev/null +++ b/Package.swift @@ -0,0 +1,33 @@ +// swift-tools-version: 5.7 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "Delta", + platforms: [.iOS(.v14)], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "Delta", + targets: ["Delta"]), + ], + dependencies: [ + .package(url: "https://github.com/Quick/Quick", from: "5.0.0"), + .package(url: "https://github.com/Quick/Nimble", from: "10.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "Delta", + dependencies: []), + .testTarget( + name: "DeltaTests", + dependencies: [ + "Delta", + .product(name: "Quick", package: "quick"), + .product(name: "Nimble", package: "nimble") + ]), + ] +) diff --git a/sources/cache.swift b/Sources/Delta/cache.swift similarity index 100% rename from sources/cache.swift rename to Sources/Delta/cache.swift diff --git a/sources/data_structures/collection_record.swift b/Sources/Delta/data_structures/collection_record.swift similarity index 100% rename from sources/data_structures/collection_record.swift rename to Sources/Delta/data_structures/collection_record.swift diff --git a/sources/data_structures/delta_change.swift b/Sources/Delta/data_structures/delta_change.swift similarity index 100% rename from sources/data_structures/delta_change.swift rename to Sources/Delta/data_structures/delta_change.swift diff --git a/sources/data_structures/delta_item.swift b/Sources/Delta/data_structures/delta_item.swift similarity index 100% rename from sources/data_structures/delta_item.swift rename to Sources/Delta/data_structures/delta_item.swift diff --git a/sources/data_structures/delta_section.swift b/Sources/Delta/data_structures/delta_section.swift similarity index 100% rename from sources/data_structures/delta_section.swift rename to Sources/Delta/data_structures/delta_section.swift diff --git a/sources/delta.swift b/Sources/Delta/delta.swift similarity index 99% rename from sources/delta.swift rename to Sources/Delta/delta.swift index c015e04..8222bb1 100644 --- a/sources/delta.swift +++ b/Sources/Delta/delta.swift @@ -42,7 +42,7 @@ func generateSectionRecords(from: [Section], to: [Section let records = changes(from: from, to: to) let recordsWithoutChange = records.filter { record in switch record { - case .change(_): + case .change(_, _): return false default: return true diff --git a/sources/extensions/UICollectionViewDelta.swift b/Sources/Delta/extensions/UICollectionViewDelta.swift similarity index 90% rename from sources/extensions/UICollectionViewDelta.swift rename to Sources/Delta/extensions/UICollectionViewDelta.swift index d7978d8..e5a11da 100644 --- a/sources/extensions/UICollectionViewDelta.swift +++ b/Sources/Delta/extensions/UICollectionViewDelta.swift @@ -2,7 +2,7 @@ import UIKit public extension UICollectionView { - public typealias CollectionViewUpdateCallback = (_ from: IndexPath, _ to: IndexPath) -> Void + typealias CollectionViewUpdateCallback = (_ from: IndexPath, _ to: IndexPath) -> Void /// Perform updates on the collection view. /// @@ -13,7 +13,7 @@ public extension UICollectionView { /// Note: due to internals in UITableView’s and UICollecitonView’s we need /// to query the cell using the old index path, and update the cell with /// data from the new index path. - public func performUpdates(_ records: [CollectionRecord], update: CollectionViewUpdateCallback? = nil) { + func performUpdates(_ records: [CollectionRecord], update: CollectionViewUpdateCallback? = nil) { self.performBatchUpdates({ for record in records { switch record { diff --git a/sources/extensions/UITableViewDelta.swift b/Sources/Delta/extensions/UITableViewDelta.swift similarity index 93% rename from sources/extensions/UITableViewDelta.swift rename to Sources/Delta/extensions/UITableViewDelta.swift index 3d78a84..67e7cdf 100644 --- a/sources/extensions/UITableViewDelta.swift +++ b/Sources/Delta/extensions/UITableViewDelta.swift @@ -2,7 +2,7 @@ import UIKit public extension UITableView { - public typealias TableViewUpdateCallback = (_ from: IndexPath, _ to: IndexPath) -> Void + typealias TableViewUpdateCallback = (_ from: IndexPath, _ to: IndexPath) -> Void /// Perform updates on the table view. /// @@ -13,7 +13,7 @@ public extension UITableView { /// Note: due to internals in UITableView’s and UICollecitonView’s we need /// to query the cell using the old index path, and update the cell with /// data from the new index path. - public func performUpdates(_ records: [CollectionRecord], update: TableViewUpdateCallback? = nil) { + func performUpdates(_ records: [CollectionRecord], update: TableViewUpdateCallback? = nil) { var changeRecords: [CollectionRecord] = [] self.beginUpdates() diff --git a/sources/processor.swift b/Sources/Delta/processor.swift similarity index 94% rename from sources/processor.swift rename to Sources/Delta/processor.swift index 0a75069..f4bb694 100644 --- a/sources/processor.swift +++ b/Sources/Delta/processor.swift @@ -10,7 +10,7 @@ func changes(from: [Item], to: [Item]) -> [DeltaChange] where I typealias DeltaCache = [Item.DeltaIdentifier: (index: Int, item: Item)] func added(_ to: [Item], fromCache: DeltaCache) -> [DeltaChange] { - return to.enumerated().flatMap { (index, element) -> DeltaChange? in + return to.enumerated().compactMap { (index, element) -> DeltaChange? in if fromCache[element.deltaIdentifier] == nil { return .add(index: index) } @@ -19,7 +19,7 @@ func changes(from: [Item], to: [Item]) -> [DeltaChange] where I } func removed(_ from: [Item], toCache: DeltaCache) -> [DeltaChange] { - return from.enumerated().flatMap { (index, item) -> DeltaChange? in + return from.enumerated().compactMap { (index, item) -> DeltaChange? in if let cacheEntry = toCache[item.deltaIdentifier] { if cacheEntry.item != item { return .change(index: cacheEntry.index, from: index) diff --git a/tests/delta_spec.swift b/Tests/DeltaTests/delta_spec.swift similarity index 99% rename from tests/delta_spec.swift rename to Tests/DeltaTests/delta_spec.swift index 8ad37cc..3936442 100644 --- a/tests/delta_spec.swift +++ b/Tests/DeltaTests/delta_spec.swift @@ -3,7 +3,7 @@ import Nimble @testable import Delta struct Section: DeltaSection, Equatable { - + let identifier: Int let items: [Model] var deltaIdentifier: Int { return self.identifier } diff --git a/tests/processor_spec.swift b/Tests/DeltaTests/processor_spec.swift similarity index 100% rename from tests/processor_spec.swift rename to Tests/DeltaTests/processor_spec.swift