@@ -12,28 +12,21 @@ import RxCocoa
12
12
import RxSwift
13
13
14
14
enum MultipleSectionModel {
15
- case ImageProvidableSection( title: String , items: [ ImageSectionItem ] )
16
- case ToggleableSection( title: String , items: [ ToggleableSectionItem ] )
17
- case StepperableSection( title: String , items: [ StepperSectionItem ] )
15
+ case ImageProvidableSection( title: String , items: [ SectionItem ] )
16
+ case ToggleableSection( title: String , items: [ SectionItem ] )
17
+ case StepperableSection( title: String , items: [ SectionItem ] )
18
18
}
19
19
20
- extension MultipleSectionModel {
21
- var title : String {
22
- switch self {
23
- case . ImageProvidableSection( title: let title, items: _) :
24
- return title
25
- case . StepperableSection( title: let title, items: _) :
26
- return title
27
- case . ToggleableSection( title: let title, items: _) :
28
- return title
29
- }
30
- }
20
+ enum SectionItem {
21
+ case ImageSectionItem( image: UIImage , title: String )
22
+ case ToggleableSectionItem( title: String , enabled: Bool )
23
+ case StepperSectionItem( title: String )
31
24
}
32
25
33
26
extension MultipleSectionModel : SectionModelType {
34
- typealias Item = Any
27
+ typealias Item = SectionItem
35
28
36
- var items : [ Item ] {
29
+ var items : [ SectionItem ] {
37
30
switch self {
38
31
case . ImageProvidableSection( title: _, items: let items) :
39
32
return items. map { $0}
@@ -49,20 +42,6 @@ extension MultipleSectionModel: SectionModelType {
49
42
}
50
43
}
51
44
52
- struct ImageSectionItem {
53
- let image : UIImage
54
- let title : String
55
- }
56
-
57
- struct ToggleableSectionItem {
58
- let title : String
59
- let enabled : Bool
60
- }
61
-
62
- struct StepperSectionItem {
63
- let title : String
64
- }
65
-
66
45
class MultipleSectionModelViewController : UIViewController {
67
46
68
47
@IBOutlet weak var tableView : UITableView !
@@ -73,11 +52,11 @@ class MultipleSectionModelViewController: UIViewController {
73
52
74
53
let sections : [ MultipleSectionModel ] = [
75
54
. ImageProvidableSection( title: " Section 1 " ,
76
- items: [ ImageSectionItem ( image: UIImage ( named: " settings " ) !, title: " General " ) ] ) ,
55
+ items: [ . ImageSectionItem( image: UIImage ( named: " settings " ) !, title: " General " ) ] ) ,
77
56
. ToggleableSection( title: " Section 2 " ,
78
- items: [ ToggleableSectionItem ( title: " On " , enabled: true ) ] ) ,
57
+ items: [ . ToggleableSectionItem( title: " On " , enabled: true ) ] ) ,
79
58
. StepperableSection( title: " Section 3 " ,
80
- items: [ StepperSectionItem ( title: " 1 " ) ] )
59
+ items: [ . StepperSectionItem( title: " 1 " ) ] )
81
60
]
82
61
83
62
let dataSource = RxTableViewSectionedReloadDataSource < MultipleSectionModel > ( )
@@ -90,25 +69,22 @@ class MultipleSectionModelViewController: UIViewController {
90
69
91
70
func skinTableViewDataSource( dataSource: RxTableViewSectionedReloadDataSource < MultipleSectionModel > ) {
92
71
dataSource. configureCell = { ( dataSource, table, idxPath, _) in
93
- switch dataSource. sectionAtIndex ( idxPath. section) {
94
- case . ImageProvidableSection( title: _, items: let items) :
95
- let item = items [ idxPath. row]
72
+ switch dataSource. itemAtIndexPath ( idxPath) {
73
+ case let . ImageSectionItem( image, title) :
96
74
let cell : ImageTitleTableViewCell = table. dequeueReusableCell ( forIndexPath: idxPath)
97
- cell. titleLabel. text = item . title
98
- cell. cellImageView. image = item . image
75
+ cell. titleLabel. text = title
76
+ cell. cellImageView. image = image
99
77
100
78
return cell
101
- case . StepperableSection( title: _, items: let items) :
102
- let item = items [ idxPath. row]
79
+ case let . StepperSectionItem( title) :
103
80
let cell : TitleSteperTableViewCell = table. dequeueReusableCell ( forIndexPath: idxPath)
104
- cell. titleLabel. text = item . title
81
+ cell. titleLabel. text = title
105
82
106
83
return cell
107
- case . ToggleableSection( title: _, items: let items) :
108
- let item = items [ idxPath. row]
84
+ case let . ToggleableSectionItem( title, enabled) :
109
85
let cell : TitleSwitchTableViewCell = table. dequeueReusableCell ( forIndexPath: idxPath)
110
- cell. switchControl. on = item . enabled
111
- cell. titleLabel. text = item . title
86
+ cell. switchControl. on = enabled
87
+ cell. titleLabel. text = title
112
88
113
89
return cell
114
90
}
@@ -122,3 +98,16 @@ class MultipleSectionModelViewController: UIViewController {
122
98
}
123
99
124
100
}
101
+
102
+ extension MultipleSectionModel {
103
+ var title : String {
104
+ switch self {
105
+ case . ImageProvidableSection( title: let title, items: _) :
106
+ return title
107
+ case . StepperableSection( title: let title, items: _) :
108
+ return title
109
+ case . ToggleableSection( title: let title, items: _) :
110
+ return title
111
+ }
112
+ }
113
+ }
0 commit comments