Bronze Challenge Chapter 27


#1

I think this one was pretty easy:

  @IBAction func addButtonPressed(_ sender: UIButton) {
    guard let todo = itemTextField.text, todo != "" else {
      return
    }
    todoList.add(todo)
    itemTextField.text = ""
    tableView.reloadData()
  }

#2

I came up with the same as you, but I also added an if statement to deal with not adding empty rows:

@IBAction func addButtonPressed(_ sender: UIButton) {
    guard let todo = itemTextField.text else {
        return
    }
    if todo != "" {
        todoList.add(todo)
        itemTextField.text = ""
        tableView.reloadData()
    }

#3

It’s better to use the isEmpty() method in String than comparing to “”, it makes the code easier to read


#4

Thanks a lot for such wonderful information and really appreciate it as it proved really helpful.