Slide 57
Slide 57 text
TEXT
EXAMPLE - TABLE VIEW CONTROLLER
class SampleViewController: UITableViewController {
let dataStore: DataStore
init(_ dataStore: DataStore) {
self.dataStore = dataStore
super.init(nibName: nil, bundle: nil)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
cell.textLabel?.text = dataStore.data(from: indexPath)
return cell
}
override func tableView(_ tableView: UITableView,
moveRowAt sourceIndexPath: IndexPath,
to destinationIndexPath: IndexPath) {
dataStore.move(from: sourceIndexPath, to: destinationIndexPath)
}
override func tableView(_ tableView: UITableView,
commit editingStyle: UITableViewCell.EditingStyle,
forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
dataStore.remove(at: indexPath)
} else if editingStyle == .insert {
dataStore.createItem(at: indexPath)
}
}
}