Menu
Coddy logo textTech

Project Overview

Part of the Logic & Flow section of Coddy's Swift journey — lesson 33 of 56.

You're going to build a tiny habit tracker. State lives in a single dictionary mapping a habit name to its history of done days for the week:

var habits: [String: [Int]] = [
    "read": [1, 3, 5],          // done on Mon, Wed, Fri
    "workout": [2, 4]           // done on Tue, Thu
]

Days are integers 1...7 for Mon...Sun. Across the next four lessons you'll add features one at a time:

  • Add a habit and mark it done
  • Compute streaks across the week
  • Print a weekly grid
  • Compare two weeks

Each lesson stands alone, you'll re-declare the dictionary at the top of every file. The state is the same shape so the methods you write transfer across lessons.

challenge icon

Challenge

Beginner

To kick off the project, write the data setup code:

  1. Initialize an empty habits dictionary ([String: [Int]])
  2. Print the count of habits
  3. Print whether the dictionary is empty

The expected output is:

0
true

Cheat sheet

A habit tracker can be modeled as a dictionary mapping habit names to arrays of completed day numbers (1...7 for Mon–Sun):

var habits: [String: [Int]] = [
    "read": [1, 3, 5],    // done on Mon, Wed, Fri
    "workout": [2, 4]     // done on Tue, Thu
]

Useful dictionary properties:

habits.count    // number of entries
habits.isEmpty  // true if no entries

Try it yourself

// TODO: declare an empty [String: [Int]], then print count and isEmpty
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Logic & Flow