I am working on the guided project in Chapter 4 of App Developement with Swift. I have entered the following code as the tutorial write:
import UIKit
class ToDoTableViewController: UITableViewController{
var todos = [ToDo]()
override func tableView( tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return todos.count
}
override func tableView( tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "ToDoCellIdentifier") else {
fatalError("Could not dequeue a cell")
}
let todo = todos[indexPath.row]
cell.textLabel?.text = todo.title
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
if let savedToDos = ToDo.loadToDos(){
todos = savedToDos
}else{
ToDo.loadSampleToDos()
}
}
Without the error, the view show the sample data on the simulator, but the compiler say that result of call "load SampleToDos()" is unused, and there is always nothing on the screen.
So, how could I resolve this problem??
import UIKit
class ToDoTableViewController: UITableViewController{
var todos = [ToDo]()
override func tableView( tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return todos.count
}
override func tableView( tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "ToDoCellIdentifier") else {
fatalError("Could not dequeue a cell")
}
let todo = todos[indexPath.row]
cell.textLabel?.text = todo.title
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
if let savedToDos = ToDo.loadToDos(){
todos = savedToDos
}else{
ToDo.loadSampleToDos()
}
}
Without the error, the view show the sample data on the simulator, but the compiler say that result of call "load SampleToDos()" is unused, and there is always nothing on the screen.
So, how could I resolve this problem??