Day 002: Making a TODO list

Jay Wilson
2 min readJan 30, 2019

Click here for the code! // Link goes to GitHub.

What I wanted to accomplish

  1. Make the UITextField work
  2. Make the button work
  3. Populate the table view

Things I accomplished:

  1. Ability to type in a task (number 1 above)
  2. Add task to the todo list (number 2 above)
  3. Dismiss the keyboard after adding a todo with the button.(number 1 & 2)
  4. The keyboard does not dismiss if using the Done key
  5. Populate the table view (number 3 above)

Things I learned

Creating a separate class for a todo list made things a little bit more difficult.

struct Todo {
var task: String
var complete:Bool = false
}
class TodoList {
private var todoList = [Todo]()
func addTodo(todo: String) {
let newTodo = Todo(task: todo, complete: false)
todoList.append(newTodo)
}
func returnList() -> Array<Todo> {
return todoList
}
func count() -> Int {
return todoList.count
}
func getTodo(index: Int) -> Todo {
return todoList[index]
}
}

For example, if I needed to grab a Todo at a specific index, I had to write my own function for it. This is also the same for getting the number of todos in the todo list.

I used the class and structs to help with organization and to also keep my data out of my ViewController.swift file.

Linking a table to a view controller

Something I had trouble on was linking the table view to the view controller. I found some online tutorials to help me, but none explained how to connect the two. I will explain it right now.

While holding option, click and drag from the table view, to ViewController.swift inside the ViewController class to make an IBOutlet.
Here is what my line of code looks like:

@IBOutlet weak var todoTable: UITableView!

If you have any questions about what I did or how I implemented anything, let me know! If you have any suggestions or other comments, let me know as well!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Jay Wilson
Jay Wilson

Written by Jay Wilson

I like to solve problems using Swift, make YouTube videos, and take photos. I also really enjoy a good cup of coffee.

No responses yet

Write a response