Copy class RemindersViewController : UIViewController {
// MARK: View vars
var tableView: UITableView !
var checbox: UIButton !
// MARK: Data vars
var reminders: [Reminder] = []
// MARK: View Lifecycle
override func viewDidLoad () {
....
}
}
We want to adapt using extensions more often to separate code. A lot of the time we have a RemindersViewController with 500 lines all in 1 class. It is very hard to read and find what you are looking for. Let us fix this with extensions.
Copy // MARK: RemindersViewController
class RemindersViewController : UIViewController {
override func viewDidLoad () {
...
}
}
// MARK: TableView Datasource
extension RemindersViewController : UITableViewDataSource {
func tableView ( _ tableView : UITableView, cellForRowAt indexPath : IndexPath) -> UITableViewCell {
...
}
}
// MARK: TableView Delegate
extension RemindersViewController : UITableDelegate {
func tableView ( _ tableView : UITableView, didSelectRowAt indexPath : IndexPath) {
...
}
}
This makes it a lot easier to read code, especially for new members. Extensions are a great way to organize code within a single file.
Copy class RouteOptionsViewController : UIViewController {
let navigationBarTitle: String = "Route Options"
...
}
Copy struct Constants {
struct Cells {
static let busIdentifier = "BusStop"
static let searchResultsIdentifier = "SearchResults"
static let cornellDestinationsIdentifier = "CornellDestinations"
}
}