Thuta Learning
Swift
AdvancedProgrammingBeginner

Mini Project

SwiftLesson 2925 min

What you'll walk away with

  • Explain the type, ownership, and runtime behavior of Mini Project
  • Test nil, error, boundary, and concurrency cases
  • Write safe and testable Swift

Explain it simply

Mini Project, in plain language

In this mini project we'll combine Swift basics to build a Course Progress Tracker . It's an example that calculates a learner's lesson progress using arrays, dictionaries, functions, optionals, loops, and conditions.

Problem → Why → Solution

The problem — why this concept matters

Leaving totalLessonCount at 0 while calculating a percentage can cause a division-by-zero issue. In a real project, you should add validation for this.

A common mistake

Assuming one sample output proves nil, ownership, actor isolation, and every error path.

Core concept — understand how it works

Build Mini Project 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. typed value
  2. Swift expression or function
  3. safe result

Explain the type, ownership, and runtime behavior of Mini Project

Core syntax or pattern

swift
struct CourseProgress {
    let learnerName: String
    var completedLessons: [String]
    let totalLessonCount: Int

    var completedCount: Int {
        completedLessons.count
    }

    var percent: Double {
        Double(completedCount) / Double(totalLessonCount) * 100
    }

    func summary() -> String {
        if completedLessons.isEmpty {
            return "\(learnerName) has not started yet."
        }

        return "\(learnerName) completed \(completedCount)/\(totalLessonCount) lessons (\(Int(percent))%)."
    }
}

var progress = CourseProgress(
    learnerName: "Nandar",
    completedLessons: ["Intro", "Variables", "Arrays"],
    totalLessonCount: 10
)

print(progress.summary())

for lesson in progress.completedLessons {
    print("Done: \(lesson)")
}

Build Mini Project 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. typed valuestruct CourseProgress {

    In this mini project we'll combine Swift basics to build a Course Progress Tracker . It's an example that calculates a learner's lesson progress using arrays, dictionaries, functions, optionals, loops, and conditions.

  2. Swift expression or function}

    Build Mini Project 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. safe result}

    Run and test an original Mini Project 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. typed value
  2. Swift expression or function
  3. safe result

Success

Explain the type, ownership, and runtime behavior of Mini Project

Failure

Leaving totalLessonCount at 0 while calculating a percentage can cause a division-by-zero issue. In a real project, you should add validation for this.

In this mini project we'll combine Swift basics to build a Course Progress Tracker. It's an example that calculates a learner's lesson progress using arrays, dictionaries, functions, optionals, loops, and conditions.

This little project gives you a logic foundation you can reuse in real apps for things like course dashboards, onboarding checklists, task trackers, and habit trackers.

swift
struct CourseProgress {
    let learnerName: String
    var completedLessons: [String]
    let totalLessonCount: Int

    var completedCount: Int {
        completedLessons.count
    }

    var percent: Double {
        Double(completedCount) / Double(totalLessonCount) * 100
    }

    func summary() -> String {
        if completedLessons.isEmpty {
            return "\(learnerName) has not started yet."
        }

        return "\(learnerName) completed \(completedCount)/\(totalLessonCount) lessons (\(Int(percent))%)."
    }
}

var progress = CourseProgress(
    learnerName: "Nandar",
    completedLessons: ["Intro", "Variables", "Arrays"],
    totalLessonCount: 10
)

print(progress.summary())

for lesson in progress.completedLessons {
    print("Done: \(lesson)")
}

CourseProgress struct stores the learner's name, completed lessons, and total lesson count. completedCount and percent are computed properties. summary() method returns the progress status as user-facing text.

You should see
Nandar completed 3/10 lessons (30%). Done: Intro Done: Variables Done: Arrays

What's Next

As a next step, add an addCompletedLesson() method and check that a new lesson isn't added twice. Then try displaying this data in a SwiftUI List view.

Real-world usage

How to apply it in a real project

Run and test an original Mini Project 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 Mini Project 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
struct CourseProgress {
    let learnerName: String
    var completedLessons: [String]
    let totalLessonCount: Int

    var completedCount: Int {
        completedLessons.count
    }

    var percent: Double {
        Double(completedCount) / Double(totalLessonCount) * 100
    }

    func summary() -> String {
        if completedLessons.isEmpty {
            return "\(learnerName) has not started yet."
        }

        return "\(learnerName) completed \(completedCount)/\(totalLessonCount) lessons (\(Int(percent))%)."
    }
}

var progress = CourseProgress(
    learnerName: "Nandar",
    completedLessons: ["Intro", "Variables", "Arrays"],
    totalLessonCount: 10
)

print(progress.summary())

for lesson in progress.completedLessons {
    print("Done: \(lesson)")
}

Expected: Explain the type, ownership, and runtime behavior of Mini Project

Show hint

Run and test an original Mini Project 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 Mini Project?

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

  • typed value → Swift expression or function → safe result
  • Build Mini Project 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.
  • Leaving totalLessonCount at 0 while calculating a percentage can cause a division-by-zero issue. In a real project, you should add validation for this.
  • Run and test an original Mini Project 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

  • Leaving totalLessonCount at 0 while calculating a percentage can cause a division-by-zero issue. In a real project, you should add validation for this.
  • Assuming one sample output proves nil, ownership, actor isolation, and every error path.
  • Bypassing compiler safety with force unwraps or unchecked shared mutable state.

Hands-on Exercise

Run and test an original Mini Project 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: Nandar completed 3/10 lessons (30%). Done: Intro Done: Variables Done: Arrays

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.

Mini Project | Thuta Learning