Skip to content

Commit 816c3b3

Browse files
committed
Add docs. Update readme with examples. Merge header and footer models to SPDiffableTextHeaderFooter.
1 parent 5b7556b commit 816c3b3

17 files changed

+241
-97
lines changed

Example/Controllers/RootController.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class RootController: DiffableTableController {
1010
enum Section: String {
1111

1212
case basic = "basic"
13+
case sidebar = "sidebar"
1314
case accessory = "accessory"
1415
case checkmark = "checkmark"
1516
case customCellProvider = "customCellProvider"
@@ -21,10 +22,12 @@ class RootController: DiffableTableController {
2122

2223
override var content: [SPDiffableSection] {
2324

25+
var content: [SPDiffableSection] = []
26+
2427
let accessorySection = SPDiffableSection(
2528
identifier: Section.accessory.identifier,
26-
header: SPDiffableTextHeader(text: "Accessory"),
27-
footer: SPDiffableTextFooter(text: "Getting default value before show. After changes in elements you can check prints in console."),
29+
header: SPDiffableTextHeaderFooter(text: "Accessory"),
30+
footer: SPDiffableTextHeaderFooter(text: "Getting default value before show. After changes in elements you can check prints in console."),
2831
items: [
2932
SPDiffableTableRowSwitch(text: "Switch", isOn: switchOn, action: { [weak self] (isOn) in
3033
guard let self = self else { return }
@@ -37,11 +40,12 @@ class RootController: DiffableTableController {
3740
})
3841
]
3942
)
43+
content.append(accessorySection)
4044

4145
let basicSection = SPDiffableSection(
4246
identifier: Section.basic.identifier,
43-
header: SPDiffableTextHeader(text: "Presenter"),
44-
footer: SPDiffableTextFooter(text: "Push in navigation processing by table controller. Sometimes you need manually deselect cell."),
47+
header: SPDiffableTextHeaderFooter(text: "Presenter"),
48+
footer: SPDiffableTextHeaderFooter(text: "Push in navigation processing by table controller. Sometimes you need manually deselect cell."),
4549
items: [
4650
SPDiffableTableRow(text: "Basic Deselect", accessoryType: .disclosureIndicator, action: { [weak self] indexPath in
4751
guard let self = self else { return }
@@ -53,6 +57,7 @@ class RootController: DiffableTableController {
5357
})
5458
]
5559
)
60+
content.append(basicSection)
5661

5762
if switchOn {
5863
accessorySection.items.insert(SPDiffableTableRow(text: "Switch Worked", accessoryType: .checkmark), at: 1)
@@ -64,27 +69,29 @@ class RootController: DiffableTableController {
6469

6570
let checkmarkSections = SPDiffableSection(
6671
identifier: Section.checkmark.identifier,
67-
footer: SPDiffableTextFooter(text: "Example how usage search by models and change checkmark without reload table."),
72+
footer: SPDiffableTextHeaderFooter(text: "Example how usage search by models and change checkmark without reload table."),
6873
items: [
6974
SPDiffableTableRow(text: "Chekmarks", accessoryType: .disclosureIndicator, action: { [weak self] indexPath in
7075
guard let self = self else { return }
7176
self.tableView.deselectRow(at: indexPath, animated: true)
7277
})
7378
]
7479
)
80+
content.append(checkmarkSections)
7581

7682
let cellProviderSection = SPDiffableSection(
7783
identifier: Section.customCellProvider.identifier,
78-
footer: SPDiffableTextFooter(text: "Also you can add more providers for specific controller, and use default and custom specially for some contorllers."),
84+
footer: SPDiffableTextHeaderFooter(text: "Also you can add more providers for specific controller, and use default and custom specially for some contorllers."),
7985
items: [
8086
SPDiffableTableRow(text: "Custom Cell Provider", accessoryType: .disclosureIndicator, action: { [weak self] indexPath in
8187
guard let self = self else { return }
8288
self.tableView.deselectRow(at: indexPath, animated: true)
8389
})
8490
]
8591
)
92+
content.append(cellProviderSection)
8693

87-
return [accessorySection, basicSection, checkmarkSections, cellProviderSection]
94+
return content
8895
}
8996

9097
private var switchOn: Bool = false {

Readme.md

Lines changed: 68 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# SPDiffable
22

3-
Apple's diffable API requerid models for each object type. If you want use it in many place, you pass many time to implemenet and get over duplicates codes. This project help you do it elegant with shared models and special cell providers for one-usage models.
3+
Apple's diffable API requerid models for each object type. If you want use it in many place, you pass many time to implemenet and get over duplicates codes. This project help you do it elegant with shared models and special cell providers for one-usage models.
44

55
If you like the project, don't forget to `put star ★` and follow me on GitHub:
66

77
[![https://github.com/ivanvorobei](https://github.com/ivanvorobei/Assets/blob/master/Buttons/follow-me-on-github.svg)](https://github.com/ivanvorobei)
88

9+
If you want help project, check [Сooperation](#сooperation) section.
10+
911
## Navigate
1012

1113
- [Requirements](#requirements)
@@ -17,8 +19,9 @@ If you like the project, don't forget to `put star ★` and follow me on GitHub:
1719
- [Usage](#usage)
1820
- [How it work](#usage)
1921
- [Apply content](#apply-content)
20-
- [Ready Use Models](#ready-use-models)
2122
- [Mediator](#mediator)
23+
- [Sidebar](#sidebar)
24+
- [Ready Use Models](#ready-use-models)
2225
- [Сooperation](#сooperation)
2326
- [Other Projects](#other-projects)
2427
- [Russian Community](#russian-community)
@@ -63,15 +66,15 @@ If you prefer not to use any of dependency managers, you can integrate `SPDiffab
6366

6467
Before read it, highly recomded check `Example` target in project. It examle show all features, like use stepper and switch, like process actions, create custom models and many other.
6568

66-
For work with diffable need create model (inside project you found some ready-use models) and do cell provider, which convert model with data to `UITableViewCell` or `UICollectionViewCell`.
69+
For work with diffable need create model (inside project you found some ready-use models) and do cell provider, which convert model with data to `UITableViewCell` or `UICollectionViewCell`. Next example for table, but all methods and class names available for collections.
6770

6871
New model shoud extend from basic class `SPDiffableItem`:
6972

7073
```swift
7174
class TableRowModel: SPDiffableItem {}
7275
```
7376

74-
After it add properties, which you want use:
77+
After it add properties, which you want use. For example:
7578

7679
```swift
7780
class TableRowMode: SPDiffableItem {
@@ -84,7 +87,7 @@ class TableRowMode: SPDiffableItem {
8487
}
8588
```
8689

87-
Last step, create table controller class and extend of `SPDiffableTableController`. Create custom cell provider, it help convert it data to table cell:
90+
Last step, create table controller class and extend of `SPDiffableTableController`. Create custom cell provider, it doing convert it data to table cell:
8891

8992
```swift
9093

@@ -115,7 +118,7 @@ override func viewDidLoad() {
115118
}
116119
```
117120

118-
For example usage you can find in project in taget `Example`.
121+
All actions similar to collections. For example usage you can find in project in taget `Example`.
119122

120123
### Apply Content
121124

@@ -125,10 +128,10 @@ Create section class:
125128
```swift
126129
let section = SPDiffableSection(
127130
identifier: "example section",
128-
header: SPDiffableTableTextHeader(text: "Header"),
129-
footer: SPDiffableTableTextFooter(text: "Footer"),
131+
header: SPDiffableTextHeaderFooter(text: "Header"),
132+
footer: SPDiffableTextHeaderFooter(text: "Footer"),
130133
items: [
131-
SPDiffableTableRow(text: "Basic Table Cell", accessoryType: .disclosureIndicator, action: { [weak self] indexPath in
134+
TableRowMode(text: "Basic Table Cell", accessoryType: .disclosureIndicator, action: { [weak self] indexPath in
132135
guard let self = self else { return }
133136
self.tableView.deselectRow(at: indexPath, animated: true)
134137
print("Tapped")
@@ -147,29 +150,6 @@ diffableDataSource?.apply(sections: content, animating: true)
147150

148151
That all. You can each time create new order or count cells and it automatically show with diffable animation. Project has some ready-use models, you can read about it next.
149152

150-
### Ready Use Models
151-
152-
It models which you can use now, it shoud close your task without code. Of couse you can create your models.
153-
Now in project you can find this ready-use models:
154-
155-
- `SPDiffableItem` it basic class. All item models shoud be extend from it model.
156-
- `SPDiffableSection` basic section class. Included footer and header, also items (cells).
157-
- `SPDiffableHeader` basic header class. All headers shoud be extend from it class.
158-
- `SPDiffableFooter` basic footer class. All footers shoud be extend from it class.
159-
160-
#### For Table:
161-
162-
- `SPDiffableTableRow` it native table view cell. Support all basic styles and action for tap event.
163-
- `SPDiffableTableRowStepper` table view cell with stepper. Has maximum value and minimum, also incuded action with passed value.
164-
- `SPDiffableTableRowSwitch` table cell with switch, included default state and action for change event.
165-
- `SPDiffableTableRowButton` table cell with style as button. Supprt table styles and action for tap.
166-
- `SPDiffableTableTextHeader` table header with text. You can see it in native table.
167-
- `SPDiffableTableTextFooter` table footer text.
168-
169-
#### For Collection:
170-
171-
Now in progress development.
172-
173153
### Mediator
174154

175155
Some methods in diffable data source can't ovveride without custom data source. It solved with mediator delegate. It simple. Next example for table. Set delegate `SPTableDiffableMediator`, all method optional:
@@ -195,12 +175,67 @@ func diffableTableView(_ tableView: UITableView, titleForHeaderInSection section
195175

196176
In protocol you can find more methods, like `canEdit` and other.
197177

178+
### Sidebar
179+
180+
Create new controller and extend from `SPDiffableSideBarController`. Remember, it available only from iOS 14. Now it abailable for `ios14` branch.
181+
182+
```swift
183+
class SidebarController: SPDiffableSideBarController {}
184+
```
185+
186+
In class available ready-use cell providers for menu item and header section. For get it shoud call:
187+
188+
```swift
189+
override func viewDidLoad() {
190+
super.viewDidLoad()
191+
setCellProviders([CellProvider.itemCellProvider, CellProvider.headerCellProvider], sections: content)
192+
}
193+
```
194+
195+
Content it array of `SPDiffableSection`. For menu model need use model `SPDiffableSideBarMenuItem`. For header and footer will create `SPDiffableSideBarHeader` model.
196+
197+
```swift
198+
SPDiffableSection(
199+
identifier: Section.library.rawValue,
200+
header: SPDiffableSideBarHeader(text: "Library", accessories: [.outlineDisclosure()]),
201+
items: [
202+
SPDiffableSideBarMenuItem(title: "Recently Added", image: UIImage(systemName: "clock"), action: { _ in }),
203+
SPDiffableSideBarMenuItem(title: "Artists", image: UIImage(systemName: "music.mic"), action: { _ in }),
204+
SPDiffableSideBarMenuItem(title: "Albums", image: UIImage(systemName: "rectangle.stack"), action: { _ in }),
205+
SPDiffableSideBarMenuItem(title: "Songs", image: UIImage(systemName: "music.note"), action: { _ in }),
206+
]
207+
)
208+
```
209+
210+
## Ready Use Models
211+
212+
It models which you can use now, it shoud close your task without code. Of couse you can create your models.
213+
Now in project you can find this ready-use models:
214+
215+
- `SPDiffableItem` it basic class. All item models shoud be extend from it model. Header and footer also.
216+
- `SPDiffableSection` section class. Included footer and header properties, also items (cells).
217+
- `SPDiffableTextHeaderFooter` header or footer class with text.
218+
219+
#### For Table:
220+
221+
- `SPDiffableTableRow` it native item for table cell. Support all basic styles and action for tap event.
222+
- `SPDiffableTableRowStepper` item for table cell with stepper. Has maximum value and minimum, also incuded action with passed value.
223+
- `SPDiffableTableRowSwitch` item for table with switch, included default state and action for change event.
224+
- `SPDiffableTableRowButton` item for table in style as button. Support table styles and action for tap.
225+
226+
#### For Collection:
227+
228+
Now in progress development.
229+
230+
- `SPDiffableSideBarMenuItem` menu item in side bar. Support accessories and actions.
231+
- `SPDiffableSideBarHeader` header model for side bar item.
232+
198233
## Сooperation
199234

200235
This project is free, but developing it takes time. Contributing to this project is a huge help. Here is list of tasks that need to be done, you can help with any:
201236

202237
- Update readme text, my English not great :(
203-
- Add docs to swift source files
238+
- Update docs to swift source files
204239

205240
## Other Projects
206241

SPDiffable.xcodeproj/project.pbxproj

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
F4D5F20F24B0D2260003EEEF /* SPCollectionDiffableDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4D5F20D24B0D1EC0003EEEF /* SPCollectionDiffableDataSource.swift */; };
2323
F4D5F21124B0D26E0003EEEF /* SPDiffableCollectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4D5F21024B0D26E0003EEEF /* SPDiffableCollectionController.swift */; };
2424
F4D5F21224B0D4D10003EEEF /* SPDiffableCollectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4D5F21024B0D26E0003EEEF /* SPDiffableCollectionController.swift */; };
25-
F4FEAEBA24A8FA3500CA513C /* SPDiffableTextHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FEAEB924A8FA3500CA513C /* SPDiffableTextHeader.swift */; };
26-
F4FEAEBC24A8FA6500CA513C /* SPDiffableTextFooter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FEAEBB24A8FA6500CA513C /* SPDiffableTextFooter.swift */; };
25+
F4FEAEBA24A8FA3500CA513C /* SPDiffableTextHeaderFooter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FEAEB924A8FA3500CA513C /* SPDiffableTextHeaderFooter.swift */; };
2726
F4FEAEBE24A8FAD200CA513C /* SPDiffableTableRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FEAEBD24A8FAD200CA513C /* SPDiffableTableRow.swift */; };
2827
F4FEAEC024A8FB1400CA513C /* SPDiffableTableRowStepper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FEAEBF24A8FB1400CA513C /* SPDiffableTableRowStepper.swift */; };
2928
F4FEAEC224A8FB4600CA513C /* SPDiffableTableRowSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FEAEC124A8FB4600CA513C /* SPDiffableTableRowSwitch.swift */; };
30-
F4FEAEC324A8FBC900CA513C /* SPDiffableTextHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FEAEB924A8FA3500CA513C /* SPDiffableTextHeader.swift */; };
31-
F4FEAEC424A8FBC900CA513C /* SPDiffableTextFooter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FEAEBB24A8FA6500CA513C /* SPDiffableTextFooter.swift */; };
29+
F4FEAEC324A8FBC900CA513C /* SPDiffableTextHeaderFooter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FEAEB924A8FA3500CA513C /* SPDiffableTextHeaderFooter.swift */; };
3230
F4FEAEC524A8FBC900CA513C /* SPDiffableTableRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FEAEBD24A8FAD200CA513C /* SPDiffableTableRow.swift */; };
3331
F4FEAEC624A8FBC900CA513C /* SPDiffableTableRowStepper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FEAEBF24A8FB1400CA513C /* SPDiffableTableRowStepper.swift */; };
3432
F4FEAEC724A8FBCA00CA513C /* SPDiffableTableRowSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FEAEC124A8FB4600CA513C /* SPDiffableTableRowSwitch.swift */; };
@@ -66,8 +64,7 @@
6664
F4954C01249B9715007072FA /* SPDiffableTableController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SPDiffableTableController.swift; sourceTree = "<group>"; };
6765
F4D5F20D24B0D1EC0003EEEF /* SPCollectionDiffableDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPCollectionDiffableDataSource.swift; sourceTree = "<group>"; };
6866
F4D5F21024B0D26E0003EEEF /* SPDiffableCollectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPDiffableCollectionController.swift; sourceTree = "<group>"; };
69-
F4FEAEB924A8FA3500CA513C /* SPDiffableTextHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPDiffableTextHeader.swift; sourceTree = "<group>"; };
70-
F4FEAEBB24A8FA6500CA513C /* SPDiffableTextFooter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPDiffableTextFooter.swift; sourceTree = "<group>"; };
67+
F4FEAEB924A8FA3500CA513C /* SPDiffableTextHeaderFooter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPDiffableTextHeaderFooter.swift; sourceTree = "<group>"; };
7168
F4FEAEBD24A8FAD200CA513C /* SPDiffableTableRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPDiffableTableRow.swift; sourceTree = "<group>"; };
7269
F4FEAEBF24A8FB1400CA513C /* SPDiffableTableRowStepper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPDiffableTableRowStepper.swift; sourceTree = "<group>"; };
7370
F4FEAEC124A8FB4600CA513C /* SPDiffableTableRowSwitch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPDiffableTableRowSwitch.swift; sourceTree = "<group>"; };
@@ -184,11 +181,9 @@
184181
isa = PBXGroup;
185182
children = (
186183
F4954BFB249B9715007072FA /* SPDiffableItem.swift */,
187-
F4FEAEB924A8FA3500CA513C /* SPDiffableTextHeader.swift */,
188-
F4FEAEBB24A8FA6500CA513C /* SPDiffableTextFooter.swift */,
184+
F4FEAEB924A8FA3500CA513C /* SPDiffableTextHeaderFooter.swift */,
189185
F4954BFD249B9715007072FA /* SPDiffableSection.swift */,
190186
F401290B24AFBA660039D039 /* SPDiffableSnapshot.swift */,
191-
F4D5F21324B0D6DA0003EEEF /* Collection */,
192187
F4FEAEB824A8FA1F00CA513C /* Table */,
193188
);
194189
path = Models;
@@ -213,13 +208,6 @@
213208
path = Collection;
214209
sourceTree = "<group>";
215210
};
216-
F4D5F21324B0D6DA0003EEEF /* Collection */ = {
217-
isa = PBXGroup;
218-
children = (
219-
);
220-
path = Collection;
221-
sourceTree = "<group>";
222-
};
223211
F4FEAEB824A8FA1F00CA513C /* Table */ = {
224212
isa = PBXGroup;
225213
children = (
@@ -376,8 +364,7 @@
376364
buildActionMask = 2147483647;
377365
files = (
378366
F4FEAEC024A8FB1400CA513C /* SPDiffableTableRowStepper.swift in Sources */,
379-
F4FEAEBA24A8FA3500CA513C /* SPDiffableTextHeader.swift in Sources */,
380-
F4FEAEBC24A8FA6500CA513C /* SPDiffableTextFooter.swift in Sources */,
367+
F4FEAEBA24A8FA3500CA513C /* SPDiffableTextHeaderFooter.swift in Sources */,
381368
F4D5F20E24B0D1EC0003EEEF /* SPCollectionDiffableDataSource.swift in Sources */,
382369
F4FEAEBE24A8FAD200CA513C /* SPDiffableTableRow.swift in Sources */,
383370
F4FEAEC924A904C100CA513C /* SPDiffableTableRowButton.swift in Sources */,
@@ -401,13 +388,12 @@
401388
F4FF9CD924A6848E006B2122 /* SPTableDiffableDataSource.swift in Sources */,
402389
F4FEAEC524A8FBC900CA513C /* SPDiffableTableRow.swift in Sources */,
403390
F4FF9CED24A69A95006B2122 /* ActionableStepper.swift in Sources */,
404-
F4FEAEC424A8FBC900CA513C /* SPDiffableTextFooter.swift in Sources */,
405391
F4FEAEC724A8FBCA00CA513C /* SPDiffableTableRowSwitch.swift in Sources */,
406392
F4FF9CD724A6848E006B2122 /* SPDiffableTableController.swift in Sources */,
407393
F4FF9CEB24A69A26006B2122 /* ActionableSwitch.swift in Sources */,
408394
F4FF9CC624A68400006B2122 /* RootController.swift in Sources */,
409395
F4FF9CDA24A6848E006B2122 /* SPTableDiffableMediator.swift in Sources */,
410-
F4FEAEC324A8FBC900CA513C /* SPDiffableTextHeader.swift in Sources */,
396+
F4FEAEC324A8FBC900CA513C /* SPDiffableTextHeaderFooter.swift in Sources */,
411397
F401290D24AFBA820039D039 /* SPDiffableSnapshot.swift in Sources */,
412398
F4FF9CD624A6848B006B2122 /* SPDiffableSection.swift in Sources */,
413399
F4FF9CC224A68400006B2122 /* AppDelegate.swift in Sources */,

0 commit comments

Comments
 (0)