Living Museum of Learning

Small circles, Big thinkers 🌱
Albert's First SwiftUI Beehive

Albert's First SwiftUI Beehive

From arranging views to describing them

Albert had learned UIKit several years earlier.

Now, with the latest version of Xcode, he opened SwiftUI for the first time.

He began by exploring the default ContentView.

The globe became a car.

VStack became HStack.

His first challenge was simple:

Four cars, arranged as two rows of two.

Without introducing loops or advanced techniques, he built the layout himself.

As the class continued, Albert experimented freely.

He duplicated views.

He changed layouts.

He observed how SwiftUI responded.

Eventually, instead of arranging cars, he began constructing a familiar pattern: a Conway's Game of Life beehive.

Every cell became a square.

Green cells represented life.

Gray cells represented empty space.

The code became long.

Very long.

But something important happened.

The preview worked.

Then the preview was rotated into landscape mode.

The beehive adapted automatically.

The layout simply reorganized itself.

Albert had not yet learned ForEach.

He had not learned data-driven views.

He had not learned grids.

Yet he discovered something fundamental.

Instead of telling every square where to go, he described relationships:

cells belong to rows
rows belong to a larger structure
squares maintain their shape
the system handles the layout

The beehive appeared.

Then the device rotated.

The beehive survived.

Albert experienced a major change in programming style.

UIKit often asks:

Where should this view go?

SwiftUI asks:

What should exist?

By building the beehive manually, he could clearly see the repeated structure before learning abstraction.

The long code was not a mistake.

It made the future visible.

When ForEach eventually arrives, it will not be introduced as a new feature.

It will solve a problem that Albert has already experienced.