This is what I have so far. I tried the code Claude used in Playground in my app but it didn't work. I get a warning with this current code Result of call to 'loadSampleToDos()' is unused and a blank screen when I run it in the simulator. I really appreciate everyone's help.
In the ToDo File:
import UIKit
struct ToDo {
var title: String
var isComplete: Bool
var dueDate: Date
var notes: String?
static func loadToDos() -> [ToDo]? {
return nil
}
static func loadSampleToDos() -> [ToDo] {
let todo1 = ToDo(title: "ToDo One", isComplete: false,
dueDate: Date(), notes: "Notes 1")
let todo2 = ToDo(title: "ToDo Two", isComplete: false,
dueDate: Date(), notes: "Notes 2")
let todo3 = ToDo(title: "ToDo Three", isComplete: false,
dueDate: Date(), notes: "Notes 3")
return [todo1, todo2, todo3]
}
}
In the ToDoTableViewController:
import UIKit
class ToDoTableViewController: UITableViewController {
var todos = [ToDo]()
override func viewDidLoad() {
super.viewDidLoad()
if let savedToDos = ToDo.loadToDos() {
todos = savedToDos
} else {
ToDo.loadSampleToDos()
}
}
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
}
}