Skip to content
This repository was archived by the owner on Aug 21, 2021. It is now read-only.

Commit aab294a

Browse files
committed
Migrate View to Swift 3
1 parent 468cc9b commit aab294a

7 files changed

+46
-59
lines changed

ExampleView/ImageDetailViewController.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ public final class ImageDetailViewController: UIViewController {
1818

1919
if let viewModel = viewModel {
2020
viewModel.image.producer
21-
.on(next: { self.imageView.image = $0 })
21+
.on(value: { self.imageView.image = $0 })
2222
.start()
2323
viewModel.tagText.producer
24-
.on(next: { self.tagLabel.text = $0 })
24+
.on(value: { self.tagLabel.text = $0 })
2525
.start()
2626
viewModel.usernameText.producer
27-
.on(next: { self.usernameLabel.text = $0 })
27+
.on(value: { self.usernameLabel.text = $0 })
2828
.start()
2929
viewModel.pageImageSizeText.producer
30-
.on(next: { self.imageSizeLabel.text = $0 })
30+
.on(value: { self.imageSizeLabel.text = $0 })
3131
.start()
3232
viewModel.viewCountText.producer
33-
.on(next: { self.viewCountLabel.text = $0 })
33+
.on(value: { self.viewCountLabel.text = $0 })
3434
.start()
3535
viewModel.downloadCountText.producer
36-
.on(next: { self.downloadCountLabel.text = $0 })
36+
.on(value: { self.downloadCountLabel.text = $0 })
3737
.start()
3838
viewModel.likeCountText.producer
39-
.on(next: { self.likeCountLabel.text = $0 })
39+
.on(value: { self.likeCountLabel.text = $0 })
4040
.start()
4141
}
4242
}
@@ -49,14 +49,14 @@ public final class ImageDetailViewController: UIViewController {
4949
@IBOutlet weak var downloadCountLabel: UILabel!
5050
@IBOutlet weak var likeCountLabel: UILabel!
5151

52-
@IBAction func openImagePage(sender: UIBarButtonItem) {
52+
@IBAction func openImagePage(_ sender: UIBarButtonItem) {
5353
let actionText = LocalizedString("ImageDetailViewController_ActionSheetViewInSafari", comment: "Action sheet button text.")
5454
let cancelText = LocalizedString("ImageDetailViewController_ActionSheetCancel", comment: "Action sheet button text.")
55-
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)
56-
alertController.addAction(UIAlertAction(title: actionText, style: .Default) { _ in
55+
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
56+
alertController.addAction(UIAlertAction(title: actionText, style: .default) { _ in
5757
self.viewModel?.openImagePage()
5858
})
59-
alertController.addAction(UIAlertAction(title: cancelText, style: .Cancel, handler: nil))
60-
self.presentViewController(alertController, animated: true, completion: nil)
59+
alertController.addAction(UIAlertAction(title: cancelText, style: .cancel, handler: nil))
60+
self.present(alertController, animated: true, completion: nil)
6161
}
6262
}

ExampleView/ImageSearchTableViewCell.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ internal final class ImageSearchTableViewCell: UITableViewCell {
1717

1818
if let viewModel = viewModel {
1919
viewModel.getPreviewImage()
20-
.takeUntil(self.racutil_prepareForReuseProducer)
21-
.on(next: { self.previewImageView.image = $0 })
20+
.take(until: self.reactive.prepareForReuse)
21+
.on(value: { self.previewImageView.image = $0 })
2222
.start()
2323
}
2424
else {

ExampleView/ImageSearchTableViewController.swift

+16-16
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
import ExampleViewModel
1010

1111
public final class ImageSearchTableViewController: UITableViewController {
12-
private var autoSearchStarted = false
12+
fileprivate var autoSearchStarted = false
1313
@IBOutlet var footerView: UIView!
1414
@IBOutlet weak var searchingIndicator: UIActivityIndicatorView!
1515

1616
public var viewModel: ImageSearchTableViewModeling? {
1717
didSet {
1818
if let viewModel = viewModel {
1919
viewModel.cellModels.producer
20-
.on(next: { _ in self.tableView.reloadData() })
20+
.on(value: { _ in self.tableView.reloadData() })
2121
.start()
2222
viewModel.searching.producer
23-
.on(next: { searching in
23+
.on(value: { searching in
2424
if searching {
2525
// Display the activity indicator at the center of the screen if the table is empty.
2626
self.footerView.frame.size.height = viewModel.cellModels.value.isEmpty
@@ -36,7 +36,7 @@ public final class ImageSearchTableViewController: UITableViewController {
3636
})
3737
.start()
3838
viewModel.errorMessage.producer
39-
.on(next: { errorMessage in
39+
.on(value: { errorMessage in
4040
if let errorMessage = errorMessage {
4141
self.displayErrorMessage(errorMessage)
4242
}
@@ -46,7 +46,7 @@ public final class ImageSearchTableViewController: UITableViewController {
4646
}
4747
}
4848

49-
public override func viewWillAppear(animated: Bool) {
49+
public override func viewWillAppear(_ animated: Bool) {
5050
super.viewWillAppear(animated)
5151

5252
if !autoSearchStarted {
@@ -55,21 +55,21 @@ public final class ImageSearchTableViewController: UITableViewController {
5555
}
5656
}
5757

58-
private func displayErrorMessage(errorMessage: String) {
58+
fileprivate func displayErrorMessage(_ errorMessage: String) {
5959
let title = LocalizedString("ImageSearchTableViewController_ErrorAlertTitle", comment: "Error alert title.")
6060
let dismissButtonText = LocalizedString("ImageSearchTableViewController_DismissButtonTitle", comment: "Dismiss button title on an alert.")
6161
let message = errorMessage
62-
let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
63-
alert.addAction(UIAlertAction(title: dismissButtonText, style: .Default) { _ in
64-
alert.dismissViewControllerAnimated(true, completion: nil)
62+
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
63+
alert.addAction(UIAlertAction(title: dismissButtonText, style: .default) { _ in
64+
alert.dismiss(animated: true, completion: nil)
6565
})
66-
self.presentViewController(alert, animated: true, completion: nil)
66+
self.present(alert, animated: true, completion: nil)
6767
}
6868
}
6969

7070
// MARK: UITableViewDataSource
7171
extension ImageSearchTableViewController {
72-
public override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
72+
public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
7373
if let viewModel = viewModel {
7474
return viewModel.cellModels.value.count
7575
}
@@ -79,12 +79,12 @@ extension ImageSearchTableViewController {
7979
// return viewModel?.cellModels.value.count ?? 0
8080
}
8181

82-
public override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
83-
let cell = tableView.dequeueReusableCellWithIdentifier("ImageSearchTableViewCell", forIndexPath: indexPath) as! ImageSearchTableViewCell
82+
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
83+
let cell = tableView.dequeueReusableCell(withIdentifier: "ImageSearchTableViewCell", for: indexPath) as! ImageSearchTableViewCell
8484
cell.viewModel = viewModel.map { $0.cellModels.value[indexPath.row] }
8585

8686
if let viewModel = viewModel
87-
where indexPath.row >= viewModel.cellModels.value.count - 1 && viewModel.loadNextPage.enabled.value {
87+
, indexPath.row >= viewModel.cellModels.value.count - 1 && viewModel.loadNextPage.isEnabled.value {
8888
viewModel.loadNextPage.apply(()).start()
8989
}
9090

@@ -94,8 +94,8 @@ extension ImageSearchTableViewController {
9494

9595
// MARK: - UITableViewDelegate
9696
extension ImageSearchTableViewController {
97-
public override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
97+
public override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
9898
viewModel?.selectCellAtIndex(indexPath.row)
99-
performSegueWithIdentifier("ImageDetailViewControllerSegue", sender: self)
99+
performSegue(withIdentifier: "ImageDetailViewControllerSegue", sender: self)
100100
}
101101
}

ExampleView/LocalizedString.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// Copyright © 2015 Swinject Contributors. All rights reserved.
77
//
88

9-
internal func LocalizedString(key: String, comment: String?) -> String {
9+
internal func LocalizedString(_ key: String, comment: String?) -> String {
1010
struct Static {
11-
static let bundle = NSBundle(identifier: "com.github.Swinject.SwinjectMVVMExample.ExampleView")!
11+
static let bundle = Bundle(identifier: "com.github.Swinject.SwinjectMVVMExample.ExampleView")!
1212
}
1313
return NSLocalizedString(key, bundle: Static.bundle, comment: comment ?? "")
1414
}

ExampleView/RACUtil.swift

-19
This file was deleted.

ExampleViewModel/ImageSearchTableViewCellModel.swift

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import ReactiveSwift
10+
import ReactiveCocoa
1011
import Result
1112
import ExampleModel
1213

0 commit comments

Comments
 (0)