Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f8cbfe1

Browse files
Complete the great renaming refactor, close jessesquires#73
Renames: - `ReusableViewFactoryProtocol` --> `ReusableViewConfigProtocol` - `ViewFactory` --> `ReusableViewConfig` - `TitledSupplementaryViewFactory` --> `TitledSupplementaryViewConfig` Other changes: - Update `init` and function parameter names to match `factory` --> `config` changes - `cellFactory:` params --> `cellConfig:` - `supplementaryFactory:` params --> `supplementaryConfig:` - Update all docs
1 parent 8d034ed commit f8cbfe1

20 files changed

+692
-709
lines changed

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ This release closes the [7.0.0 milestone](https://github.com/jessesquires/JSQDat
1414
- Converted to Swift 4.0
1515
- iOS 9.0 minimum now required
1616
- tvOS 10.0 minimum now required
17+
- **Significant renaming refactor:** renamed all "factory" references to "config", see #73 for details and reasoning
18+
- `ReusableViewFactoryProtocol` --> `ReusableViewConfigProtocol`
19+
- `ViewFactory` --> `ReusableViewConfig`
20+
- `TitledSupplementaryViewFactory` --> `TitledSupplementaryViewConfig`
21+
- Updated function param names `cellFactory:` --> `cellConfig:`
22+
- Updated function param names `supplementaryFactory:` --> `supplementaryConfig:`
1723

1824
## New
1925

‎Example/Example.xcodeproj/project.pbxproj‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
886EC7B21CFF2E5F00BDE6FA /* CollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 886EC79F1CFF2E5E00BDE6FA /* CollectionViewCell.swift */; };
1818
886EC7B31CFF2E5F00BDE6FA /* CollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 886EC7A01CFF2E5E00BDE6FA /* CollectionViewCell.xib */; };
1919
886EC7B41CFF2E5F00BDE6FA /* CollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 886EC7A11CFF2E5E00BDE6FA /* CollectionViewController.swift */; };
20-
886EC7B51CFF2E5F00BDE6FA /* ComposedSupplementaryViewFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 886EC7A21CFF2E5E00BDE6FA /* ComposedSupplementaryViewFactory.swift */; };
20+
886EC7B51CFF2E5F00BDE6FA /* ComposedCollectionSupplementaryViewConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 886EC7A21CFF2E5E00BDE6FA /* ComposedCollectionSupplementaryViewConfig.swift */; };
2121
886EC7B71CFF2E5F00BDE6FA /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 886EC7A41CFF2E5E00BDE6FA /* Extensions.swift */; };
2222
886EC7B81CFF2E5F00BDE6FA /* FetchedCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 886EC7A51CFF2E5E00BDE6FA /* FetchedCollectionViewController.swift */; };
2323
886EC7B91CFF2E5F00BDE6FA /* FetchedTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 886EC7A61CFF2E5E00BDE6FA /* FetchedTableViewController.swift */; };
@@ -29,7 +29,7 @@
2929
88AD28A71D1F97BC000492FC /* ExampleModel.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 88AD28A31D1F97A3000492FC /* ExampleModel.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3030
88DCAD911CB87E6700C018AF /* JSQDataSourcesKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88DCAD8E1CB87DD900C018AF /* JSQDataSourcesKit.framework */; };
3131
88DCAD921CB87E6700C018AF /* JSQDataSourcesKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 88DCAD8E1CB87DD900C018AF /* JSQDataSourcesKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
32-
BF21124D1D46663600F1840A /* ComposedCellViewFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF21124C1D46663600F1840A /* ComposedCellViewFactory.swift */; };
32+
BF21124D1D46663600F1840A /* ComposedCellViewConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF21124C1D46663600F1840A /* ComposedCellViewConfig.swift */; };
3333
BF5C03641D3FED6700CA3EA3 /* FancyCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = BF5C03631D3FED6700CA3EA3 /* FancyCollectionViewCell.xib */; };
3434
BF5C03691D3FED7F00CA3EA3 /* FancyCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF5C03681D3FED7F00CA3EA3 /* FancyCollectionViewCell.swift */; };
3535
BF6AEBD11D3E91A40048AE97 /* MixedCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF6AEBD01D3E91A40048AE97 /* MixedCollectionViewController.swift */; };
@@ -130,7 +130,7 @@
130130
886EC79F1CFF2E5E00BDE6FA /* CollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewCell.swift; sourceTree = "<group>"; };
131131
886EC7A01CFF2E5E00BDE6FA /* CollectionViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CollectionViewCell.xib; sourceTree = "<group>"; };
132132
886EC7A11CFF2E5E00BDE6FA /* CollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewController.swift; sourceTree = "<group>"; };
133-
886EC7A21CFF2E5E00BDE6FA /* ComposedSupplementaryViewFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComposedSupplementaryViewFactory.swift; sourceTree = "<group>"; };
133+
886EC7A21CFF2E5E00BDE6FA /* ComposedCollectionSupplementaryViewConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComposedCollectionSupplementaryViewConfig.swift; sourceTree = "<group>"; };
134134
886EC7A41CFF2E5E00BDE6FA /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
135135
886EC7A51CFF2E5E00BDE6FA /* FetchedCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedCollectionViewController.swift; sourceTree = "<group>"; };
136136
886EC7A61CFF2E5E00BDE6FA /* FetchedTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedTableViewController.swift; sourceTree = "<group>"; };
@@ -143,7 +143,7 @@
143143
88AD289D1D1F97A3000492FC /* ExampleModel.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ExampleModel.xcodeproj; path = ExampleModel/ExampleModel.xcodeproj; sourceTree = "<group>"; };
144144
88DB89C11A86D1A900DED153 /* DataSources.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DataSources.app; sourceTree = BUILT_PRODUCTS_DIR; };
145145
88DCAD881CB87DD900C018AF /* JSQDataSourcesKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JSQDataSourcesKit.xcodeproj; path = ../JSQDataSourcesKit.xcodeproj; sourceTree = "<group>"; };
146-
BF21124C1D46663600F1840A /* ComposedCellViewFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComposedCellViewFactory.swift; sourceTree = "<group>"; };
146+
BF21124C1D46663600F1840A /* ComposedCellViewConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComposedCellViewConfig.swift; sourceTree = "<group>"; };
147147
BF5C03631D3FED6700CA3EA3 /* FancyCollectionViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FancyCollectionViewCell.xib; sourceTree = "<group>"; };
148148
BF5C03681D3FED7F00CA3EA3 /* FancyCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FancyCollectionViewCell.swift; sourceTree = "<group>"; };
149149
BF6AEBD01D3E91A40048AE97 /* MixedCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MixedCollectionViewController.swift; sourceTree = "<group>"; };
@@ -203,8 +203,8 @@
203203
886EC79F1CFF2E5E00BDE6FA /* CollectionViewCell.swift */,
204204
886EC7A01CFF2E5E00BDE6FA /* CollectionViewCell.xib */,
205205
886EC7A11CFF2E5E00BDE6FA /* CollectionViewController.swift */,
206-
BF21124C1D46663600F1840A /* ComposedCellViewFactory.swift */,
207-
886EC7A21CFF2E5E00BDE6FA /* ComposedSupplementaryViewFactory.swift */,
206+
BF21124C1D46663600F1840A /* ComposedCellViewConfig.swift */,
207+
886EC7A21CFF2E5E00BDE6FA /* ComposedCollectionSupplementaryViewConfig.swift */,
208208
886EC7A41CFF2E5E00BDE6FA /* Extensions.swift */,
209209
BF5C03681D3FED7F00CA3EA3 /* FancyCollectionViewCell.swift */,
210210
BF5C03631D3FED6700CA3EA3 /* FancyCollectionViewCell.xib */,
@@ -476,14 +476,14 @@
476476
886EC7B41CFF2E5F00BDE6FA /* CollectionViewController.swift in Sources */,
477477
886EC7BA1CFF2E5F00BDE6FA /* Helpers.swift in Sources */,
478478
886EC7B81CFF2E5F00BDE6FA /* FetchedCollectionViewController.swift in Sources */,
479-
BF21124D1D46663600F1840A /* ComposedCellViewFactory.swift in Sources */,
479+
BF21124D1D46663600F1840A /* ComposedCellViewConfig.swift in Sources */,
480480
886EC7BE1CFF2E5F00BDE6FA /* TableViewController.swift in Sources */,
481481
886EC7C01CFF2E5F00BDE6FA /* ViewController.swift in Sources */,
482482
886EC7B21CFF2E5F00BDE6FA /* CollectionViewCell.swift in Sources */,
483483
BF5C03691D3FED7F00CA3EA3 /* FancyCollectionViewCell.swift in Sources */,
484484
BF6AEBD11D3E91A40048AE97 /* MixedCollectionViewController.swift in Sources */,
485485
886EC7AF1CFF2E5F00BDE6FA /* AppDelegate.swift in Sources */,
486-
886EC7B51CFF2E5F00BDE6FA /* ComposedSupplementaryViewFactory.swift in Sources */,
486+
886EC7B51CFF2E5F00BDE6FA /* ComposedCollectionSupplementaryViewConfig.swift in Sources */,
487487
);
488488
runOnlyForDeploymentPostprocessing = 0;
489489
};

‎Example/Sources/CollectionViewController.swift‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,47 @@ import JSQDataSourcesKit
2222

2323

2424
final class CollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
25-
25+
2626
typealias Source = DataSource< Section<CellViewModel> >
27-
typealias CollectionCellFactory = ViewFactory<CellViewModel, CollectionViewCell>
28-
typealias HeaderViewFactory = TitledSupplementaryViewFactory<CellViewModel>
29-
30-
var dataSourceProvider: DataSourceProvider<Source, CollectionCellFactory,HeaderViewFactory>?
31-
27+
typealias CollectionCellConfig = ReusableViewConfig<CellViewModel, CollectionViewCell>
28+
typealias HeaderViewConfig = TitledSupplementaryViewConfig<CellViewModel>
29+
30+
var dataSourceProvider: DataSourceProvider<Source, CollectionCellConfig,HeaderViewConfig>?
31+
3232
override func viewDidLoad() {
3333
super.viewDidLoad()
3434
configureCollectionView(collectionView!)
35-
35+
3636
// 1. create view models
3737
let section0 = Section(items: CellViewModel(), CellViewModel(), CellViewModel())
3838
let section1 = Section(items: CellViewModel(), CellViewModel(), CellViewModel(), CellViewModel(), CellViewModel(), CellViewModel())
3939
let section2 = Section(items: CellViewModel())
4040
let dataSource = DataSource(sections: section0, section1, section2)
41-
42-
// 2. create cell factory
43-
let cellFactory = ViewFactory(reuseIdentifier: CellId) { (cell, model: CellViewModel?, type, collectionView, indexPath) -> CollectionViewCell in
41+
42+
// 2. create cell config
43+
let cellConfig = ReusableViewConfig(reuseIdentifier: CellId) { (cell, model: CellViewModel?, type, collectionView, indexPath) -> CollectionViewCell in
4444
cell.label.text = model!.text + "\n\(indexPath.section), \(indexPath.item)"
4545
cell.accessibilityIdentifier = "\(indexPath.section), \(indexPath.item)"
4646
return cell
4747
}
48-
49-
// 3. create supplementary view factory
50-
let headerFactory = TitledSupplementaryViewFactory { (header, item: CellViewModel?, kind, collectionView, indexPath) -> TitledSupplementaryView in
48+
49+
// 3. create supplementary view config
50+
let headerConfig = TitledSupplementaryViewConfig { (header, item: CellViewModel?, kind, collectionView, indexPath) -> TitledSupplementaryView in
5151
header.label.text = "Section \(indexPath.section)"
5252
header.backgroundColor = .darkGray
5353
header.label.textColor = .white
5454
return header
5555
}
56-
56+
5757
// 4. create data source provider
5858
self.dataSourceProvider = DataSourceProvider(dataSource: dataSource,
59-
cellFactory: cellFactory,
60-
supplementaryFactory: headerFactory)
61-
59+
cellConfig: cellConfig,
60+
supplementaryConfig: headerConfig)
61+
6262
// 5. set data source
6363
collectionView?.dataSource = self.dataSourceProvider?.collectionViewDataSource
6464
}
65-
65+
6666
func collectionView(_ collectionView: UICollectionView,
6767
layout collectionViewLayout: UICollectionViewLayout,
6868
referenceSizeForHeaderInSection section: Int) -> CGSize {

‎Example/Sources/ComposedCellViewFactory.swift‎ renamed to ‎Example/Sources/ComposedCellViewConfig.swift‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,39 @@ import UIKit
2020
import JSQDataSourcesKit
2121

2222
/*
23-
Example of a composed factory for collection view cells.
23+
Example of a composed config for collection view cells.
2424
Used for headers and footers in `MixedCollectionViewController` in the demo
2525
*/
26-
struct ComposedCellViewFactory:ReusableViewFactoryProtocol {
27-
28-
let standardCellFactory:ViewFactory<CellViewModel, CollectionViewCell>
29-
30-
let fancyCellFactory:ViewFactory<FancyViewModel, FancyCollectionViewCell>
31-
32-
init(standardCellFactory:ViewFactory<CellViewModel, CollectionViewCell>,
33-
fancyCellFactory:ViewFactory<FancyViewModel, FancyCollectionViewCell>) {
34-
self.standardCellFactory = standardCellFactory
35-
self.fancyCellFactory = fancyCellFactory
26+
struct ComposedCellViewConfig:ReusableViewConfigProtocol {
27+
28+
let standardCellConfig:ReusableViewConfig<CellViewModel, CollectionViewCell>
29+
30+
let fancyCellConfig:ReusableViewConfig<FancyViewModel, FancyCollectionViewCell>
31+
32+
init(standardCellConfig:ReusableViewConfig<CellViewModel, CollectionViewCell>,
33+
fancyCellConfig:ReusableViewConfig<FancyViewModel, FancyCollectionViewCell>) {
34+
self.standardCellConfig = standardCellConfig
35+
self.fancyCellConfig = fancyCellConfig
3636
}
37-
37+
3838
func reuseIdentiferFor(item: MixedItem?, type: ReusableViewType, indexPath: IndexPath) -> String {
3939
return item!.reuseIdentifier
4040
}
41-
41+
4242
func configure(view: UICollectionViewCell, item: MixedItem?, type: ReusableViewType, parentView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell {
4343
view.accessibilityIdentifier = "\(indexPath.section), \(indexPath.item)"
44-
44+
4545
guard let model = item else {
4646
return view
4747
}
48-
48+
4949
switch model {
5050
case let .standard(standardModel):
5151
let cell = view as! CollectionViewCell
52-
return standardCellFactory.configure(view: cell, item: standardModel, type: type, parentView: parentView, indexPath: indexPath)
52+
return standardCellConfig.configure(view: cell, item: standardModel, type: type, parentView: parentView, indexPath: indexPath)
5353
case let .fancy(fancyModel):
5454
let cell = view as! FancyCollectionViewCell
55-
return fancyCellFactory.configure(view: cell, item: fancyModel, type: type, parentView: parentView, indexPath: indexPath)
55+
return fancyCellConfig.configure(view: cell, item: fancyModel, type: type, parentView: parentView, indexPath: indexPath)
5656
}
5757
}
5858
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// Created by Jesse Squires
3+
// https://www.jessesquires.com
4+
//
5+
//
6+
// Documentation
7+
// https://jessesquires.github.io/JSQDataSourcesKit
8+
//
9+
//
10+
// GitHub
11+
// https://github.com/jessesquires/JSQDataSourcesKit
12+
//
13+
//
14+
// License
15+
// Copyright © 2015-present Jesse Squires
16+
// Released under an MIT license: https://opensource.org/licenses/MIT
17+
//
18+
19+
import Foundation
20+
import UIKit
21+
import JSQDataSourcesKit
22+
23+
/*
24+
Example of a composed config for supplementary views.
25+
Used for headers and footers in `FetchedCollectionViewController` in the demo
26+
*/
27+
public struct ComposedCollectionSupplementaryViewConfig <Item>: ReusableViewConfigProtocol {
28+
29+
public let headerConfig: TitledSupplementaryViewConfig<Item>
30+
31+
public let footerConfig: TitledSupplementaryViewConfig<Item>
32+
33+
public init(headerConfig: TitledSupplementaryViewConfig<Item>,
34+
footerConfig: TitledSupplementaryViewConfig<Item>) {
35+
self.headerConfig = headerConfig
36+
self.footerConfig = footerConfig
37+
}
38+
39+
public func reuseIdentiferFor(item: Item?, type: ReusableViewType, indexPath: IndexPath) -> String {
40+
return TitledSupplementaryView.identifier
41+
}
42+
43+
public func configure(view: TitledSupplementaryView,
44+
item: Item?,
45+
type: ReusableViewType,
46+
parentView: UICollectionView,
47+
indexPath: IndexPath) -> TitledSupplementaryView {
48+
switch type {
49+
case .supplementaryView(kind: UICollectionElementKindSectionHeader):
50+
return headerConfig.configure(view: view, item: item, type: type, parentView: parentView, indexPath: indexPath)
51+
case .supplementaryView(kind: UICollectionElementKindSectionFooter):
52+
return footerConfig.configure(view: view, item: item, type: type, parentView: parentView, indexPath: indexPath)
53+
default:
54+
fatalError("attempt to dequeue supplementary view with unknown kind: \(type)")
55+
}
56+
}
57+
}

‎Example/Sources/ComposedSupplementaryViewFactory.swift‎

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /