Skip to content

Commit 4350789

Browse files
committed
Adaptations for Swift-3.0
1 parent df9f56d commit 4350789

30 files changed

+373
-410
lines changed

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "ReactiveX/RxSwift" ~> 2.3.1
1+
github "ReactiveX/RxSwift" "swift-3.0"

Cartfile.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "ReactiveX/RxSwift" "2.5.0"
1+
github "ReactiveX/RxSwift" "b47ce13eaea5929bd18758eef8828d6c8ce2a02b"

Example/Example1_CustomizationUsingTableViewDelegate.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ class CustomizationUsingTableViewDelegate : UIViewController {
4040
override func viewDidLoad() {
4141
super.viewDidLoad()
4242

43-
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
43+
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
4444

4545
let dataSource = RxTableViewSectionedAnimatedDataSource<MySection>()
4646

4747
dataSource.configureCell = { ds, tv, ip, item in
48-
let cell = tv.dequeueReusableCellWithIdentifier("Cell") ?? UITableViewCell(style: .Default, reuseIdentifier: "Cell")
48+
let cell = tv.dequeueReusableCell(withIdentifier: "Cell") ?? UITableViewCell(style: .default, reuseIdentifier: "Cell")
4949
cell.textLabel?.text = "Item \(item)"
5050

5151
return cell
@@ -78,7 +78,7 @@ class CustomizationUsingTableViewDelegate : UIViewController {
7878
}
7979

8080
extension CustomizationUsingTableViewDelegate : UITableViewDelegate {
81-
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
81+
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: IndexPath) -> CGFloat {
8282

8383
// you can also fetch item
8484
guard let item = dataSource?.itemAtIndexPath(indexPath),
@@ -90,4 +90,4 @@ extension CustomizationUsingTableViewDelegate : UITableViewDelegate {
9090

9191
return CGFloat(40 + item)
9292
}
93-
}
93+
}

Example/Example2_RandomizedSectionsAnimation.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ class ViewController: UIViewController {
103103
// MARK: Skinning
104104
extension ViewController {
105105

106-
func skinTableViewDataSource(dataSource: RxTableViewSectionedDataSource<NumberSection>) {
106+
func skinTableViewDataSource(_ dataSource: RxTableViewSectionedDataSource<NumberSection>) {
107107
dataSource.configureCell = { (_, tv, ip, i) in
108-
let cell = tv.dequeueReusableCellWithIdentifier("Cell") ?? UITableViewCell(style:.Default, reuseIdentifier: "Cell")
108+
let cell = tv.dequeueReusableCell(withIdentifier: "Cell") ?? UITableViewCell(style:.default, reuseIdentifier: "Cell")
109109

110110
cell.textLabel!.text = "\(i)"
111111

@@ -117,17 +117,17 @@ extension ViewController {
117117
}
118118
}
119119

120-
func skinCollectionViewDataSource(dataSource: CollectionViewSectionedDataSource<NumberSection>) {
120+
func skinCollectionViewDataSource(_ dataSource: CollectionViewSectionedDataSource<NumberSection>) {
121121
dataSource.configureCell = { (_, cv, ip, i) in
122-
let cell = cv.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: ip) as! NumberCell
122+
let cell = cv.dequeueReusableCell(withReuseIdentifier: "Cell", for: ip) as! NumberCell
123123

124124
cell.value!.text = "\(i)"
125125

126126
return cell
127127
}
128128

129129
dataSource.supplementaryViewFactory = { (ds ,cv, kind, ip) in
130-
let section = cv.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "Section", forIndexPath: ip) as! NumberSectionView
130+
let section = cv.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Section", for: ip) as! NumberSectionView
131131

132132
section.value!.text = "\(ds.sectionAtIndex(ip.section).header)"
133133

@@ -151,7 +151,7 @@ extension ViewController {
151151
*/
152152

153153
return (0 ..< nSections).map { (i: Int) in
154-
NumberSection(header: "Section \(i + 1)", numbers: $(Array(i * nItems ..< (i + 1) * nItems)), updated: NSDate())
154+
NumberSection(header: "Section \(i + 1)", numbers: $(Array(i * nItems ..< (i + 1) * nItems)), updated: Date())
155155
}
156156
}
157157
else {
@@ -163,19 +163,19 @@ extension ViewController {
163163
}
164164

165165
let _initialValue: [NumberSection] = [
166-
NumberSection(header: "section 1", numbers: $([1, 2, 3]), updated: NSDate()),
167-
NumberSection(header: "section 2", numbers: $([4, 5, 6]), updated: NSDate()),
168-
NumberSection(header: "section 3", numbers: $([7, 8, 9]), updated: NSDate()),
169-
NumberSection(header: "section 4", numbers: $([10, 11, 12]), updated: NSDate()),
170-
NumberSection(header: "section 5", numbers: $([13, 14, 15]), updated: NSDate()),
171-
NumberSection(header: "section 6", numbers: $([16, 17, 18]), updated: NSDate()),
172-
NumberSection(header: "section 7", numbers: $([19, 20, 21]), updated: NSDate()),
173-
NumberSection(header: "section 8", numbers: $([22, 23, 24]), updated: NSDate()),
174-
NumberSection(header: "section 9", numbers: $([25, 26, 27]), updated: NSDate()),
175-
NumberSection(header: "section 10", numbers: $([28, 29, 30]), updated: NSDate())
166+
NumberSection(header: "section 1", numbers: $([1, 2, 3]), updated: Date()),
167+
NumberSection(header: "section 2", numbers: $([4, 5, 6]), updated: Date()),
168+
NumberSection(header: "section 3", numbers: $([7, 8, 9]), updated: Date()),
169+
NumberSection(header: "section 4", numbers: $([10, 11, 12]), updated: Date()),
170+
NumberSection(header: "section 5", numbers: $([13, 14, 15]), updated: Date()),
171+
NumberSection(header: "section 6", numbers: $([16, 17, 18]), updated: Date()),
172+
NumberSection(header: "section 7", numbers: $([19, 20, 21]), updated: Date()),
173+
NumberSection(header: "section 8", numbers: $([22, 23, 24]), updated: Date()),
174+
NumberSection(header: "section 9", numbers: $([25, 26, 27]), updated: Date()),
175+
NumberSection(header: "section 10", numbers: $([28, 29, 30]), updated: Date())
176176
]
177177

178-
func $(numbers: [Int]) -> [IntItem] {
179-
return numbers.map { IntItem(number: $0, date: NSDate()) }
178+
func $(_ numbers: [Int]) -> [IntItem] {
179+
return numbers.map { IntItem(number: $0, date: Date()) }
180180
}
181181

Example/Example3_TableViewEditing.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class EditingExampleViewController: UIViewController {
2323
super.viewDidLoad()
2424

2525
let dataSource = RxTableViewSectionedAnimatedDataSource<NumberSection>()
26-
let sections: [NumberSection] = [NumberSection(header: "Section 1", numbers: [], updated: NSDate()),
27-
NumberSection(header: "Section 2", numbers: [], updated: NSDate()),
28-
NumberSection(header: "Section 3", numbers: [], updated: NSDate())]
26+
let sections: [NumberSection] = [NumberSection(header: "Section 1", numbers: [], updated: Date()),
27+
NumberSection(header: "Section 2", numbers: [], updated: Date()),
28+
NumberSection(header: "Section 3", numbers: [], updated: Date())]
2929

3030
let initialState = SectionedTableViewState(sections: sections)
3131
let add3ItemsAddStart = Observable.of((), (), ())
@@ -39,11 +39,11 @@ class EditingExampleViewController: UIViewController {
3939
let movedCommand = tableView.rx_itemMoved
4040
.map(TableViewEditingCommand.MoveItem)
4141

42-
skinTableViewDataSource(dataSource)
42+
skinTableViewDataSource(dataSource: dataSource)
4343
Observable.of(addCommand, deleteCommand, movedCommand)
4444
.merge()
45-
.scan(initialState) {
46-
return $0.executeCommand($1)
45+
.scan(initialState) { (state: SectionedTableViewState, command: TableViewEditingCommand) -> SectionedTableViewState in
46+
return state.execute(command: command)
4747
}
4848
.startWith(initialState)
4949
.map {
@@ -54,19 +54,19 @@ class EditingExampleViewController: UIViewController {
5454
.addDisposableTo(disposeBag)
5555
}
5656

57-
override func viewDidAppear(animated: Bool) {
57+
override func viewDidAppear(_ animated: Bool) {
5858
super.viewDidAppear(animated)
5959
tableView.setEditing(true, animated: true)
6060
}
6161

6262
func skinTableViewDataSource(dataSource: RxTableViewSectionedAnimatedDataSource<NumberSection>) {
6363

64-
dataSource.animationConfiguration = AnimationConfiguration(insertAnimation: .Top,
65-
reloadAnimation: .Fade,
66-
deleteAnimation: .Left)
64+
dataSource.animationConfiguration = AnimationConfiguration(insertAnimation: .top,
65+
reloadAnimation: .fade,
66+
deleteAnimation: .left)
6767

6868
dataSource.configureCell = { (dataSource, table, idxPath, item) in
69-
let cell = table.dequeueReusableCellWithIdentifier("Cell", forIndexPath: idxPath)
69+
let cell = table.dequeueReusableCell(withIdentifier: "Cell", for: idxPath)
7070

7171
cell.textLabel?.text = "\(item)"
7272

@@ -88,8 +88,8 @@ class EditingExampleViewController: UIViewController {
8888

8989
enum TableViewEditingCommand {
9090
case AppendItem(item: IntItem, section: Int)
91-
case MoveItem(sourceIndex: NSIndexPath, destinationIndex: NSIndexPath)
92-
case DeleteItem(NSIndexPath)
91+
case MoveItem(sourceIndex: IndexPath, destinationIndex: IndexPath)
92+
case DeleteItem(IndexPath)
9393
}
9494

9595
// This is the part
@@ -101,7 +101,7 @@ struct SectionedTableViewState {
101101
self.sections = sections
102102
}
103103

104-
func executeCommand(command: TableViewEditingCommand) -> SectionedTableViewState {
104+
func execute(command: TableViewEditingCommand) -> SectionedTableViewState {
105105
switch command {
106106
case .AppendItem(let appendEvent):
107107
var sections = self.sections
@@ -111,7 +111,7 @@ struct SectionedTableViewState {
111111
case .DeleteItem(let indexPath):
112112
var sections = self.sections
113113
var items = sections[indexPath.section].items
114-
items.removeAtIndex(indexPath.row)
114+
items.remove(at: indexPath.row)
115115
sections[indexPath.section] = NumberSection(original: sections[indexPath.section], items: items)
116116
return SectionedTableViewState(sections: sections)
117117
case .MoveItem(let moveEvent):
@@ -120,15 +120,15 @@ struct SectionedTableViewState {
120120
var destinationItems = sections[moveEvent.destinationIndex.section].items
121121

122122
if moveEvent.sourceIndex.section == moveEvent.destinationIndex.section {
123-
destinationItems.insert(destinationItems.removeAtIndex(moveEvent.sourceIndex.row),
124-
atIndex: moveEvent.destinationIndex.row)
123+
destinationItems.insert(destinationItems.remove(at: moveEvent.sourceIndex.row),
124+
at: moveEvent.destinationIndex.row)
125125
let destinationSection = NumberSection(original: sections[moveEvent.destinationIndex.section], items: destinationItems)
126126
sections[moveEvent.sourceIndex.section] = destinationSection
127127

128128
return SectionedTableViewState(sections: sections)
129129
} else {
130-
let item = sourceItems.removeAtIndex(moveEvent.sourceIndex.row)
131-
destinationItems.insert(item, atIndex: moveEvent.destinationIndex.row)
130+
let item = sourceItems.remove(at: moveEvent.sourceIndex.row)
131+
destinationItems.insert(item, at: moveEvent.destinationIndex.row)
132132
let sourceSection = NumberSection(original: sections[moveEvent.sourceIndex.section], items: sourceItems)
133133
let destinationSection = NumberSection(original: sections[moveEvent.destinationIndex.section], items: destinationItems)
134134
sections[moveEvent.sourceIndex.section] = sourceSection
@@ -144,7 +144,7 @@ extension TableViewEditingCommand {
144144
static func addRandomItem() -> TableViewEditingCommand {
145145
let randSection = Int(arc4random_uniform(UInt32(3)))
146146
let number = Int(arc4random_uniform(UInt32(100)))
147-
let item = IntItem(number: number, date: NSDate())
147+
let item = IntItem(number: number, date: Date())
148148
return TableViewEditingCommand.AppendItem(item: item, section: randSection)
149149
}
150150
}

Example/Example4_DifferentSectionAndItemTypes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class MultipleSectionModelViewController: UIViewController {
3838
.addDisposableTo(disposeBag)
3939
}
4040

41-
func skinTableViewDataSource(dataSource: RxTableViewSectionedReloadDataSource<MultipleSectionModel>) {
41+
func skinTableViewDataSource(_ dataSource: RxTableViewSectionedReloadDataSource<MultipleSectionModel>) {
4242
dataSource.configureCell = { (dataSource, table, idxPath, _) in
4343
switch dataSource.itemAtIndexPath(idxPath) {
4444
case let .ImageSectionItem(image, title):
@@ -54,7 +54,7 @@ class MultipleSectionModelViewController: UIViewController {
5454
return cell
5555
case let .ToggleableSectionItem(title, enabled):
5656
let cell: TitleSwitchTableViewCell = table.dequeueReusableCell(forIndexPath: idxPath)
57-
cell.switchControl.on = enabled
57+
cell.switchControl.isOn = enabled
5858
cell.titleLabel.text = title
5959

6060
return cell

Example/Support/AppDelegate.swift

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
17+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1818
// Override point for customization after application launch.
1919
return true
2020
}
2121

22-
func applicationWillResignActive(application: UIApplication) {
23-
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24-
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25-
}
26-
27-
func applicationDidEnterBackground(application: UIApplication) {
28-
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30-
}
31-
32-
func applicationWillEnterForeground(application: UIApplication) {
33-
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34-
}
35-
36-
func applicationDidBecomeActive(application: UIApplication) {
37-
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38-
}
39-
40-
func applicationWillTerminate(application: UIApplication) {
41-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42-
}
43-
44-
4522
}
4623

Example/Support/NumberSection.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ struct NumberSection {
1616

1717
var numbers: [IntItem]
1818

19-
var updated: NSDate
19+
var updated: Date
2020

21-
init(header: String, numbers: [Item], updated: NSDate) {
21+
init(header: String, numbers: [Item], updated: Date) {
2222
self.header = header
2323
self.numbers = numbers
2424
self.updated = updated
@@ -28,7 +28,7 @@ struct NumberSection {
2828

2929
struct IntItem {
3030
let number: Int
31-
let date: NSDate
31+
let date: Date
3232
}
3333

3434
// MARK: Just extensions to say how to determine identity and how to determine is entity updated
@@ -71,7 +71,7 @@ extension IntItem
7171

7272
// equatable, this is needed to detect changes
7373
func == (lhs: IntItem, rhs: IntItem) -> Bool {
74-
return lhs.number == rhs.number && lhs.date.isEqualToDate(rhs.date)
74+
return lhs.number == rhs.number && lhs.date == rhs.date
7575
}
7676

7777
// MARK: Some nice extensions
@@ -88,4 +88,4 @@ extension IntItem
8888
var description: String {
8989
return "\(number)"
9090
}
91-
}
91+
}

0 commit comments

Comments
 (0)