Menu
Coddy logo textTech

To-Do List

Part of the Introduction to SwiftUI section of Coddy's Swift journey. Lesson 49 of 50.

challenge icon

Challenge

Hard

Build a to-do list with the Todo struct:

  • a TextField with the placeholder New task (identifier field) and an Add button that appends a Todo with the typed title to a todos state array (starting empty) and clears the field
  • a List (identifier list) with one Toggle per task, titled with the task and bound to its done
  • a text (identifier progress) that reads 1 of 2 done, counting the tasks whose done is true

Try it yourself

import SwiftUI

@main
struct CoddyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

All lessons in Introduction to SwiftUI

Practice on your own: Swift playground