Thuta Learning
AdvancedProgrammingbeginner

Mini Project

Relax. We'll talk through this in plain words — no textbook voice.

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.

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.
Mini Project | Thuta Learning