In this assignment, you’ll practice building layouts with stacks, extracting reusable views, and passing data through variables. The theme: Harry Potter house crests. You’ll pick two houses, style an information card for each, and use SwiftUI’s extract-view feature to avoid duplicating code.
Before You Begin
- Not sure which houses represent you? Take the Wizarding World sorting quiz.
- Download the house crest images, unzip the file, and drag all four images into
Assets.xcassets. - You only need to build one house card first — you’ll extract and reuse it for the second house in the next step.
Step 1: Choose Your Houses
Pick the two houses that best represent you. You’ll use them throughout the rest of the assignment.
Step 2: Build One House Card
Build a polished card for your first house only. Style it to meet all of these requirements:
- Display the house crest image alongside the house name, animal, traits, and color values.
- Make each line of text a different style — vary the size, weight, and font to establish a clear visual hierarchy.
- Apply a background color that matches the house (use the RGB values in the reference table below). Add rounded corners with a corner radius of 10.
- Add at least 10 points of padding inside the background area.

Step 3: Extract the View
Once your first card looks the way you want, extract and reuse it for the second house:
- Command-click the outer
VStackthat contains your card, then choose Extract View. In Xcode 16+, use Refactor → Extract Selection to File instead. - Create variables in the extracted struct for values that differ between houses: image name, house name, animal, traits, and background color.
- Use the extracted view to display your second house, passing its own values to each variable.

Step 4: Style ContentView
Link to both house cards from ContentView. Style the links to look polished — use rounded corners, matching dimensions, a background color, and descriptive labels.
House Reference
| House | Animal | Traits | RGB Color |
|---|---|---|---|
| Gryffindor | Lion | Courage, Bravery, Determination | 150, 51, 56 |
| Hufflepuff | Badger | Fairness, Hard Work, Loyalty | 241, 204, 96 |
| Ravenclaw | Eagle | Wisdom, Creativity, Curiosity | 41, 50, 101 |
| Slytherin | Serpent | Ambition, Cunning, Resourcefulness | 27, 117, 71 |