Thuta Learning
Swift
ProjectsProgrammingBeginner

Project: Task Manager App - Part 1 (Setup + Core Structure)

SwiftLesson 3030 min

What you'll walk away with

  • Explain the type, ownership, and runtime behavior of Project: Task Manager App - Part 1 (Setup + Core Structure)
  • Test nil, error, boundary, and concurrency cases
  • Write safe and testable Swift

Explain it simply

Project: Task Manager App - Part 1 (Setup + Core Structure), in plain language

In this mini project we'll build a Task Manager app that manages a to-do-style task list. We'll split it into 3 parts, and in Part 1 we'll lay down the data model and core structure first. We'll define a Task struct as a value type holding title, isDone, and priority for each task, and use a Priority enum for priority levels. Since TaskManager needs to hold the task list and handle add/print operations, we'll write it as a class — a reference type. This is hands-on practice directly applying the struct-vs-class and enum topics.

Problem → Why → Solution

The problem — why this concept matters

Treating the Task struct like a mutable reference type, the way a class works, and writing var manager: Task without understanding copy semantics

A common mistake

Not noticing duplicate ids when assigning id manually (we'll fix this with validation in Part 3)

Core concept — understand how it works

Build Project: Task Manager App - Part 1 (Setup + Core Structure) in vertical slices that separate UI, domain state, persistence or services, and tests. Cover normal, boundary, nil, error, cancellation, and concurrency paths without blocking main-actor work.

Mental model
  1. project requirements
  2. components, state, and services
  3. tested UI

Explain the type, ownership, and runtime behavior of Project: Task Manager App - Part 1 (Setup + Core Structure)

Core syntax or pattern

swift
enum Priority: String {
    case low = "Low"
    case medium = "Medium"
    case high = "High"
}

struct Task {
    let id: Int
    var title: String
    var priority: Priority
    var isDone: Bool = false
}

class TaskManager {
    private var tasks: [Task] = []

    func addTask(title: String, priority: Priority) {
        let newTask = Task(id: tasks.count + 1, title: title, priority: priority)
        tasks.append(newTask)
    }

    func printAllTasks() {
        print("----- Task List -----")
        for task in tasks {
            let status = task.isDone ? "Done" : "Pending"
            print("#\(task.id) [\(task.priority.rawValue)] \(task.title) - \(status)")
        }
    }
}

let manager = TaskManager()
manager.addTask(title: "Review Swift optionals", priority: .high)
manager.addTask(title: "Write Struct versus Class notes", priority: .medium)
manager.printAllTasks()

Build Project: Task Manager App - Part 1 (Setup + Core Structure) in vertical slices that separate UI, domain state, persistence or services, and tests. Cover normal, boundary, nil, error, cancellation, and concurrency paths without blocking main-actor work.

Read the code step by step

  1. project requirementsenum Priority: String {

    In this mini project we'll build a Task Manager app that manages a to-do-style task list. We'll split it into 3 parts, and in Part 1 we'll lay down the data model and core structure first. We'll define a Task struct as a value type holding title, isDone, and priority for each task, and use a Priority enum for priority levels. Since TaskManager needs to hold the task list and handle add/print operations, we'll write it as a class — a reference type. This is hands-on practice directly applying the struct-vs-class and enum topics.

  2. components, state, and serviceslet newTask = Task(id: tasks.count + 1, title: title,...

    Build Project: Task Manager App - Part 1 (Setup + Core Structure) in vertical slices that separate UI, domain state, persistence or services, and tests. Cover normal, boundary, nil, error, cancellation, and concurrency paths without blocking main-actor work.

  3. tested UImanager.printAllTasks()

    Run and test an original Project: Task Manager App - Part 1 (Setup + Core Structure) example with empty, nil, boundary, invalid, error, and cancellation cases. Verify value copying, shared references, actor isolation, and main-actor effects where relevant.

Execution flow
  1. project requirements
  2. components, state, and services
  3. tested UI

Success

Explain the type, ownership, and runtime behavior of Project: Task Manager App - Part 1 (Setup + Core Structure)

Failure

Treating the Task struct like a mutable reference type, the way a class works, and writing var manager: Task without understanding copy semantics

Let's think about this for a second

In this mini project we'll build a Task Manager app that manages a to-do-style task list. We'll split it into 3 parts, and in Part 1 we'll lay down the data model and core structure first. We'll define a Task struct as a value type holding title, isDone, and priority for each task, and use a Priority enum for priority levels. Since TaskManager needs to hold the task list and handle add/print operations, we'll write it as a class — a reference type. This is hands-on practice directly applying the struct-vs-class and enum topics.

Let's build it

Build a Priority enum with three cases: low, medium, high. Give the Task struct four fields: id (Int), title (String), priority (Priority), isDone (Bool, default false). Build a TaskManager class with a private var tasks: [Task] = [] array, and write an addTask(title:priority:) method that auto-generates the id using tasks.count + 1. Write a printAllTasks() method that formats and prints each task with its id, title, priority, and status. In Part 2, we'll keep building on this TaskManager by adding filter/sort features.

Sample Code

swift
enum Priority: String {
    case low = "Low"
    case medium = "Medium"
    case high = "High"
}

struct Task {
    let id: Int
    var title: String
    var priority: Priority
    var isDone: Bool = false
}

class TaskManager {
    private var tasks: [Task] = []

    func addTask(title: String, priority: Priority) {
        let newTask = Task(id: tasks.count + 1, title: title, priority: priority)
        tasks.append(newTask)
    }

    func printAllTasks() {
        print("----- Task List -----")
        for task in tasks {
            let status = task.isDone ? "Done" : "Pending"
            print("#\(task.id) [\(task.priority.rawValue)] \(task.title) - \(status)")
        }
    }
}

let manager = TaskManager()
manager.addTask(title: "Review Swift optionals", priority: .high)
manager.addTask(title: "Write Struct versus Class notes", priority: .medium)
manager.printAllTasks()
You should see
The console prints a task list header followed by two neatly formatted lines containing id, priority, title, and status.

Give it 5 minutes

Add an urgent case to Priority, add about three tasks with addTask, then call printAllTasks() and check whether the output format is correct. Spend about 5 minutes on it.

One thing to watch out for

Keep the Task struct as a value type — understanding that appending it to an array makes a copy will make writing the update logic in Part 2 much easier.

Real-world usage

How to apply it in a real project

Run and test an original Project: Task Manager App - Part 1 (Setup + Core Structure) example with empty, nil, boundary, invalid, error, and cancellation cases. Verify value copying, shared references, actor isolation, and main-actor effects where relevant.

Mini challenge

Build it yourself

Run and test an original Project: Task Manager App - Part 1 (Setup + Core Structure) example with empty, nil, boundary, invalid, error, and cancellation cases. Verify value copying, shared references, actor isolation, and main-actor effects where relevant.

  • Rebuild the example without copying it
  • Test a normal input and an edge case
  • Predict the compiler or output result before running it
swift
enum Priority: String {
    case low = "Low"
    case medium = "Medium"
    case high = "High"
}

struct Task {
    let id: Int
    var title: String
    var priority: Priority
    var isDone: Bool = false
}

class TaskManager {
    private var tasks: [Task] = []

    func addTask(title: String, priority: Priority) {
        let newTask = Task(id: tasks.count + 1, title: title, priority: priority)
        tasks.append(newTask)
    }

    func printAllTasks() {
        print("----- Task List -----")
        for task in tasks {
            let status = task.isDone ? "Done" : "Pending"
            print("#\(task.id) [\(task.priority.rawValue)] \(task.title) - \(status)")
        }
    }
}

let manager = TaskManager()
manager.addTask(title: "Review Swift optionals", priority: .high)
manager.addTask(title: "Write Struct versus Class notes", priority: .medium)
manager.printAllTasks()

Expected: Explain the type, ownership, and runtime behavior of Project: Task Manager App - Part 1 (Setup + Core Structure)

Show hint

Run and test an original Project: Task Manager App - Part 1 (Setup + Core Structure) example with empty, nil, boundary, invalid, error, and cancellation cases. Verify value copying, shared references, actor isolation, and main-actor effects where relevant.

Quick quiz 1 / 3

What best describes the core idea of Project: Task Manager App - Part 1 (Setup + Core Structure)?

Quick quiz 2 / 3

Which mistake should you avoid first?

Quick quiz 3 / 3

How should this be applied in a real project?

What to remember

  • project requirements → components, state, and services → tested UI
  • Build Project: Task Manager App - Part 1 (Setup + Core Structure) in vertical slices that separate UI, domain state, persistence or services, and tests. Cover normal, boundary, nil, error, cancellation, and concurrency paths without blocking main-actor work.
  • Treating the Task struct like a mutable reference type, the way a class works, and writing var manager: Task without understanding copy semantics
  • Run and test an original Project: Task Manager App - Part 1 (Setup + Core Structure) example with empty, nil, boundary, invalid, error, and cancellation cases. Verify value copying, shared references, actor isolation, and main-actor effects where relevant.

The Swift Programming Language — Swift.org

Easy traps

  • Treating the Task struct like a mutable reference type, the way a class works, and writing var manager: Task without understanding copy semantics
  • Not noticing duplicate ids when assigning id manually (we'll fix this with validation in Part 3)
  • Assuming one sample output proves nil, ownership, actor isolation, and every error path.

Hands-on Exercise

Run and test an original Project: Task Manager App - Part 1 (Setup + Core Structure) example with empty, nil, boundary, invalid, error, and cancellation cases. Verify value copying, shared references, actor isolation, and main-actor effects where relevant.

You'll know it worked when: The console prints a task list header followed by two neatly formatted lines containing id, priority, title, and status.

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Project: Task Manager App - Part 1 (Setup + Core Structure) | Thuta Learning