← All daysDay 42 of 49 · Part 11: Platform features and shipping
Day 42

Dark mode and theming

These are the lesson notes for this day. Its build-along tutorial and flash cards have not been written yet.

Lesson 48

Dark mode and theming

Use semantic colors — .primary, .secondary, Color(.systemBackground), and colors defined in the asset catalog with a light and a dark variant — and your interface adapts to dark mode by itself. Read the current mode with @Environment(\.colorScheme) only when you need different logic, not merely different colors. For a theme that applies to the whole app, place it in the environment so that every view reads from one place.

Exercise

Preview every screen of your app in light and dark mode side by side. Replace every hard-coded color with a semantic color or one from the asset catalog.

After this lesson you should be able to answer
  1. What is a semantic color?
  2. How do you define a color that has a light and a dark variant?
  3. How do you preview a view in dark mode?
Resources