Skip to content

Commit d5c33cf

Browse files
committed
Improves naming of the generic arguments.
1 parent 1b7808a commit d5c33cf

17 files changed

+138
-165
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ All notable changes to this project will be documented in this file.
99
* Makes SectionModel and AnimatableSectionModel equatable when their model and items conforms to equatable.
1010
* Resolved issues with Animated Collection View #60
1111

12+
## [4.0.0](https://github.com/RxSwiftCommunity/RxDataSources/releases/tag/4.0.0)
13+
14+
* Swift 5.0
15+
* Fixes problems with `UICollectionView` animation crashes.
16+
* Improves readability by renaming short generic names to more descriptive names.
17+
* Changes frameworks to be static libs. (Carthage integration)
18+
1219
## [3.1.0](https://github.com/RxSwiftCommunity/RxDataSources/releases/tag/3.1.0)
1320

1421
* Xcode 10.0 compatibility.

Package.resolved

Lines changed: 0 additions & 16 deletions
This file was deleted.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ let package = Package(
1212
.library(name: "Differentiator", targets: ["Differentiator"]),
1313
],
1414
dependencies: [
15-
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "4.5.0")),
15+
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "5.0.0")),
1616
],
1717
targets: [
1818
.target(name: "RxDataSources", dependencies: ["Differentiator", "RxSwift", "RxCocoa"]),
1919
.target(name: "Differentiator"),
2020
.testTarget(name: "RxDataSourcesTests", dependencies: ["RxDataSources"]),
2121
],
22-
swiftLanguageVersions: [.v4_2, .v5]
22+
swiftLanguageVersions: [.v5]
2323
)

RxDataSources.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
03EEEE851F5B7D5C006068BC /* Randomizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Randomizer.swift; sourceTree = "<group>"; };
7272
03EEEE861F5B7D5C006068BC /* s.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = s.swift; sourceTree = "<group>"; };
7373
03EEEE871F5B7D5C006068BC /* XCTest+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "XCTest+Extensions.swift"; sourceTree = "<group>"; };
74+
1E38DA4A22778D1A00C07A09 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
7475
C81905AE1DEA019100AE679C /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7576
C81FBF451F3B9CED0094061E /* Differentiator.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Differentiator.podspec; sourceTree = "<group>"; };
7677
C81FBF5B1F3B9D4C0094061E /* Array+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+Extensions.swift"; sourceTree = "<group>"; };
@@ -205,6 +206,7 @@
205206
C8984C501C36AF35001E4272 = {
206207
isa = PBXGroup;
207208
children = (
209+
1E38DA4A22778D1A00C07A09 /* Package.swift */,
208210
C8B438561F3BA49F00B6A80B /* CHANGELOG.md */,
209211
C81FBF5A1F3B9CF10094061E /* Podspecs */,
210212
C85EE5461C36F1FC0090614D /* Sources */,

Sources/Differentiator/AnimatableSectionModel.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ extension AnimatableSectionModel
4848

4949
}
5050

51-
#if swift(>=4.1)
5251
extension AnimatableSectionModel
5352
: Equatable where Section: Equatable {
5453

@@ -57,4 +56,3 @@ extension AnimatableSectionModel
5756
&& lhs.items == rhs.items
5857
}
5958
}
60-
#endif

Sources/Differentiator/Changeset.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
import Foundation
1010

11-
public struct Changeset<S: SectionModelType> {
12-
public typealias I = S.Item
11+
public struct Changeset<Section: SectionModelType> {
12+
public typealias Item = Section.Item
1313

1414
public let reloadData: Bool
1515

16-
public let originalSections: [S]
17-
public let finalSections: [S]
16+
public let originalSections: [Section]
17+
public let finalSections: [Section]
1818

1919
public let insertedSections: [Int]
2020
public let deletedSections: [Int]
@@ -27,8 +27,8 @@ public struct Changeset<S: SectionModelType> {
2727
public let updatedItems: [ItemPath]
2828

2929
init(reloadData: Bool = false,
30-
originalSections: [S] = [],
31-
finalSections: [S] = [],
30+
originalSections: [Section] = [],
31+
finalSections: [Section] = [],
3232
insertedSections: [Int] = [],
3333
deletedSections: [Int] = [],
3434
movedSections: [(from: Int, to: Int)] = [],
@@ -55,8 +55,8 @@ public struct Changeset<S: SectionModelType> {
5555
self.updatedItems = updatedItems
5656
}
5757

58-
public static func initialValue(_ sections: [S]) -> Changeset<S> {
59-
return Changeset<S>(
58+
public static func initialValue(_ sections: [Section]) -> Changeset<Section> {
59+
return Changeset<Section>(
6060
reloadData: true,
6161
finalSections: sections,
6262
insertedSections: Array(0 ..< sections.count) as [Int]

Sources/Differentiator/Diff.swift

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public enum Diff {
104104
}
105105
}
106106

107-
private static func indexSections<S: AnimatableSectionModelType>(_ sections: [S]) throws -> [S.Identity : Int] {
108-
var indexedSections: [S.Identity : Int] = [:]
107+
private static func indexSections<Section: AnimatableSectionModelType>(_ sections: [Section]) throws -> [Section.Identity : Int] {
108+
var indexedSections: [Section.Identity : Int] = [:]
109109
for (i, section) in sections.enumerated() {
110110
guard indexedSections[section.identity] == nil else {
111111
#if DEBUG
@@ -126,12 +126,12 @@ public enum Diff {
126126
//================================================================================
127127
// swift dictionary optimizations {
128128

129-
private struct OptimizedIdentity<E: Hashable> : Hashable {
129+
private struct OptimizedIdentity<Identity: Hashable> : Hashable {
130130

131-
let identity: UnsafePointer<E>
131+
let identity: UnsafePointer<Identity>
132132
private let cachedHashValue: Int
133133

134-
init(_ identity: UnsafePointer<E>) {
134+
init(_ identity: UnsafePointer<Identity>) {
135135
self.identity = identity
136136
self.cachedHashValue = identity.pointee.hashValue
137137
}
@@ -140,7 +140,7 @@ public enum Diff {
140140
hasher.combine(self.cachedHashValue)
141141
}
142142

143-
static func == (lhs: OptimizedIdentity<E>, rhs: OptimizedIdentity<E>) -> Bool {
143+
static func == (lhs: OptimizedIdentity<Identity>, rhs: OptimizedIdentity<Identity>) -> Bool {
144144
if lhs.hashValue != rhs.hashValue {
145145
return false
146146
}
@@ -157,7 +157,7 @@ public enum Diff {
157157
private static func calculateAssociatedData<Item: IdentifiableType>(
158158
initialItemCache: ContiguousArray<ContiguousArray<Item>>,
159159
finalItemCache: ContiguousArray<ContiguousArray<Item>>
160-
) throws
160+
) throws
161161
-> (ContiguousArray<ContiguousArray<ItemAssociatedData>>, ContiguousArray<ContiguousArray<ItemAssociatedData>>) {
162162

163163
typealias Identity = Item.Identity
@@ -354,15 +354,15 @@ public enum Diff {
354354
//
355355
// There maybe exists a better division, but time will tell.
356356
//
357-
public static func differencesForSectionedView<S: AnimatableSectionModelType>(
358-
initialSections: [S],
359-
finalSections: [S])
360-
throws -> [Changeset<S>] {
361-
typealias I = S.Item
357+
public static func differencesForSectionedView<Section: AnimatableSectionModelType>(
358+
initialSections: [Section],
359+
finalSections: [Section])
360+
throws -> [Changeset<Section>] {
361+
typealias I = Section.Item
362362

363-
var result: [Changeset<S>] = []
363+
var result: [Changeset<Section>] = []
364364

365-
var sectionCommands = try CommandGenerator<S>.generatorForInitialSections(initialSections, finalSections: finalSections)
365+
var sectionCommands = try CommandGenerator<Section>.generatorForInitialSections(initialSections, finalSections: finalSections)
366366

367367
result.append(contentsOf: try sectionCommands.generateDeleteSectionsDeletedItemsAndUpdatedItems())
368368
result.append(contentsOf: try sectionCommands.generateInsertAndMoveSections())
@@ -371,20 +371,11 @@ public enum Diff {
371371
return result
372372
}
373373

374+
private struct CommandGenerator<Section: AnimatableSectionModelType> {
375+
typealias Item = Section.Item
374376

375-
@available(*, deprecated, renamed: "differencesForSectionedView(initialSections:finalSections:)")
376-
public static func differencesForSectionedView<S: AnimatableSectionModelType>(
377-
_ initialSections: [S],
378-
finalSections: [S])
379-
throws -> [Changeset<S>] {
380-
return try differencesForSectionedView(initialSections: initialSections, finalSections: finalSections)
381-
}
382-
383-
private struct CommandGenerator<S: AnimatableSectionModelType> {
384-
typealias Item = S.Item
385-
386-
let initialSections: [S]
387-
let finalSections: [S]
377+
let initialSections: [Section]
378+
let finalSections: [Section]
388379

389380
let initialSectionData: ContiguousArray<SectionAssociatedData>
390381
let finalSectionData: ContiguousArray<SectionAssociatedData>
@@ -396,9 +387,9 @@ public enum Diff {
396387
let finalItemCache: ContiguousArray<ContiguousArray<Item>>
397388

398389
static func generatorForInitialSections(
399-
_ initialSections: [S],
400-
finalSections: [S]
401-
) throws -> CommandGenerator<S> {
390+
_ initialSections: [Section],
391+
finalSections: [Section]
392+
) throws -> CommandGenerator<Section> {
402393

403394
let (initialSectionData, finalSectionData) = try calculateSectionMovements(initialSections: initialSections, finalSections: finalSections)
404395

@@ -417,7 +408,7 @@ public enum Diff {
417408
finalSectionData: finalSectionData
418409
)
419410

420-
return CommandGenerator<S>(
411+
return CommandGenerator<Section>(
421412
initialSections: initialSections,
422413
finalSections: finalSections,
423414

@@ -526,7 +517,7 @@ public enum Diff {
526517
return (initialItemData, finalItemData)
527518
}
528519

529-
static func calculateSectionMovements(initialSections: [S], finalSections: [S]) throws
520+
static func calculateSectionMovements(initialSections: [Section], finalSections: [Section]) throws
530521
-> (ContiguousArray<SectionAssociatedData>, ContiguousArray<SectionAssociatedData>) {
531522

532523
let initialSectionIndexes = try Diff.indexSections(initialSections)
@@ -609,13 +600,13 @@ public enum Diff {
609600
return (initialSectionData, finalSectionData)
610601
}
611602

612-
mutating func generateDeleteSectionsDeletedItemsAndUpdatedItems() throws -> [Changeset<S>] {
603+
mutating func generateDeleteSectionsDeletedItemsAndUpdatedItems() throws -> [Changeset<Section>] {
613604
var deletedSections = [Int]()
614605

615606
var deletedItems = [ItemPath]()
616607
var updatedItems = [ItemPath]()
617608

618-
var afterDeleteState = [S]()
609+
var afterDeleteState = [Section]()
619610

620611
// mark deleted items {
621612
// 1rst stage again (I know, I know ...)
@@ -630,7 +621,7 @@ public enum Diff {
630621
continue
631622
}
632623

633-
var afterDeleteItems: [S.Item] = []
624+
var afterDeleteItems: [Section.Item] = []
634625
for j in 0 ..< initialItems.count {
635626
let event = initialItemData[i][j].event
636627
switch event {
@@ -648,7 +639,7 @@ public enum Diff {
648639
}
649640
}
650641

651-
afterDeleteState.append(try S.init(safeOriginal: initialSections[i], safeItems: afterDeleteItems))
642+
afterDeleteState.append(try Section.init(safeOriginal: initialSections[i], safeItems: afterDeleteItems))
652643
}
653644
// }
654645

@@ -664,7 +655,7 @@ public enum Diff {
664655
)]
665656
}
666657

667-
func generateInsertAndMoveSections() throws -> [Changeset<S>] {
658+
func generateInsertAndMoveSections() throws -> [Changeset<Section>] {
668659

669660
var movedSections = [(from: Int, to: Int)]()
670661
var insertedSections = [Int]()
@@ -696,7 +687,7 @@ public enum Diff {
696687
}
697688

698689
// sections should be in place, but items should be original without deleted ones
699-
let sectionsAfterChange: [S] = try self.finalSections.enumerated().map { i, s -> S in
690+
let sectionsAfterChange: [Section] = try self.finalSections.enumerated().map { i, s -> Section in
700691
let event = self.finalSectionData[i].event
701692

702693
if event == .inserted {
@@ -707,7 +698,7 @@ public enum Diff {
707698
let originalSectionIndex = try finalSectionData[i].moveIndex.unwrap()
708699
let originalSection = initialSections[originalSectionIndex]
709700

710-
var items: [S.Item] = []
701+
var items: [Section.Item] = []
711702
items.reserveCapacity(originalSection.items.count)
712703
let itemAssociatedData = self.initialItemData[originalSectionIndex]
713704
for j in 0 ..< originalSection.items.count {
@@ -725,7 +716,7 @@ public enum Diff {
725716
items.append(finalItemCache[finalIndex.sectionIndex][finalIndex.itemIndex])
726717
}
727718

728-
let modifiedSection = try S.init(safeOriginal: s, safeItems: items)
719+
let modifiedSection = try Section.init(safeOriginal: s, safeItems: items)
729720

730721
return modifiedSection
731722
}
@@ -742,7 +733,7 @@ public enum Diff {
742733
)]
743734
}
744735

745-
mutating func generateInsertAndMovedItems() throws -> [Changeset<S>] {
736+
mutating func generateInsertAndMovedItems() throws -> [Changeset<Section>] {
746737
var insertedItems = [ItemPath]()
747738
var movedItems = [(from: ItemPath, to: ItemPath)]()
748739

Sources/Differentiator/SectionModel.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ extension SectionModel {
4343
}
4444
}
4545

46-
#if swift(>=4.1)
4746
extension SectionModel
4847
: Equatable where Section: Equatable, ItemType: Equatable {
4948

@@ -52,4 +51,3 @@ extension SectionModel
5251
&& lhs.items == rhs.items
5352
}
5453
}
55-
#endif

Sources/RxDataSources/AnimationConfiguration.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
Exposes custom animation styles for insertion, deletion and reloading behavior.
1515
*/
1616
public struct AnimationConfiguration {
17-
public let insertAnimation: UITableViewRowAnimation
18-
public let reloadAnimation: UITableViewRowAnimation
19-
public let deleteAnimation: UITableViewRowAnimation
17+
public let insertAnimation: UITableView.RowAnimation
18+
public let reloadAnimation: UITableView.RowAnimation
19+
public let deleteAnimation: UITableView.RowAnimation
2020

21-
public init(insertAnimation: UITableViewRowAnimation = .automatic,
22-
reloadAnimation: UITableViewRowAnimation = .automatic,
23-
deleteAnimation: UITableViewRowAnimation = .automatic) {
21+
public init(insertAnimation: UITableView.RowAnimation = .automatic,
22+
reloadAnimation: UITableView.RowAnimation = .automatic,
23+
deleteAnimation: UITableView.RowAnimation = .automatic) {
2424
self.insertAnimation = insertAnimation
2525
self.reloadAnimation = reloadAnimation
2626
self.deleteAnimation = deleteAnimation

0 commit comments

Comments
 (0)