9
9
import ExampleViewModel
10
10
11
11
public final class ImageSearchTableViewController : UITableViewController {
12
- private var autoSearchStarted = false
12
+ fileprivate var autoSearchStarted = false
13
13
@IBOutlet var footerView : UIView !
14
14
@IBOutlet weak var searchingIndicator : UIActivityIndicatorView !
15
15
16
16
public var viewModel : ImageSearchTableViewModeling ? {
17
17
didSet {
18
18
if let viewModel = viewModel {
19
19
viewModel. cellModels. producer
20
- . on ( next : { _ in self . tableView. reloadData ( ) } )
20
+ . on ( value : { _ in self . tableView. reloadData ( ) } )
21
21
. start ( )
22
22
viewModel. searching. producer
23
- . on ( next : { searching in
23
+ . on ( value : { searching in
24
24
if searching {
25
25
// Display the activity indicator at the center of the screen if the table is empty.
26
26
self . footerView. frame. size. height = viewModel. cellModels. value. isEmpty
@@ -36,7 +36,7 @@ public final class ImageSearchTableViewController: UITableViewController {
36
36
} )
37
37
. start ( )
38
38
viewModel. errorMessage. producer
39
- . on ( next : { errorMessage in
39
+ . on ( value : { errorMessage in
40
40
if let errorMessage = errorMessage {
41
41
self . displayErrorMessage ( errorMessage)
42
42
}
@@ -46,7 +46,7 @@ public final class ImageSearchTableViewController: UITableViewController {
46
46
}
47
47
}
48
48
49
- public override func viewWillAppear( animated: Bool ) {
49
+ public override func viewWillAppear( _ animated: Bool ) {
50
50
super. viewWillAppear ( animated)
51
51
52
52
if !autoSearchStarted {
@@ -55,21 +55,21 @@ public final class ImageSearchTableViewController: UITableViewController {
55
55
}
56
56
}
57
57
58
- private func displayErrorMessage( errorMessage: String ) {
58
+ fileprivate func displayErrorMessage( _ errorMessage: String ) {
59
59
let title = LocalizedString ( " ImageSearchTableViewController_ErrorAlertTitle " , comment: " Error alert title. " )
60
60
let dismissButtonText = LocalizedString ( " ImageSearchTableViewController_DismissButtonTitle " , comment: " Dismiss button title on an alert. " )
61
61
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 )
65
65
} )
66
- self . presentViewController ( alert, animated: true , completion: nil )
66
+ self . present ( alert, animated: true , completion: nil )
67
67
}
68
68
}
69
69
70
70
// MARK: UITableViewDataSource
71
71
extension ImageSearchTableViewController {
72
- public override func tableView( tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
72
+ public override func tableView( _ tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
73
73
if let viewModel = viewModel {
74
74
return viewModel. cellModels. value. count
75
75
}
@@ -79,12 +79,12 @@ extension ImageSearchTableViewController {
79
79
// return viewModel?.cellModels.value.count ?? 0
80
80
}
81
81
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
84
84
cell. viewModel = viewModel. map { $0. cellModels. value [ indexPath. row] }
85
85
86
86
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 {
88
88
viewModel. loadNextPage. apply ( ( ) ) . start ( )
89
89
}
90
90
@@ -94,8 +94,8 @@ extension ImageSearchTableViewController {
94
94
95
95
// MARK: - UITableViewDelegate
96
96
extension ImageSearchTableViewController {
97
- public override func tableView( tableView: UITableView , didSelectRowAtIndexPath indexPath: NSIndexPath ) {
97
+ public override func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
98
98
viewModel? . selectCellAtIndex ( indexPath. row)
99
- performSegueWithIdentifier ( " ImageDetailViewControllerSegue " , sender: self )
99
+ performSegue ( withIdentifier : " ImageDetailViewControllerSegue " , sender: self )
100
100
}
101
101
}
0 commit comments