Better Programming

Advice for programmers.

Follow publication

Member-only story

The SwiftUI Layout Protocol in iOS 16

A practical look at the new protocol introduced in SwiftUI

Mark Lucking
Better Programming
Published in
3 min readOct 10, 2022
Photo by Esther Jiao on Unsplash

When I started coding, there were no frameworks to speak of. When you wanted to plot a circle on the screen, it took dozens or more lines of code than today. As science has developed, the concept of abstraction and frameworks has become the way forward.

Today, if I want to draw a circle using the SwiftUI framework, it takes just a couple of lines. It is good, but there is a price to pay; the higher the abstraction, the less flexibility you have, a trade-off.

When Apple launched SwiftUI, one of the goals was to make the layout of screens far easier than it has been for the past two decades with UIKit. It introduces three primary containers to lay out your windows: HStack, VStack, and ZStack. But for some, it was too high a price to do the layouts they had gotten used to in UIKit. They looked complex and messy in SwiftUI.

Apple has tried to address this by introducing the layout protocol, exposing the underbelly of those principle containers so that you can change how they behave. Join me in this article to look at some practical uses and implementations of this new protocol to let us create our containers with their own layout rules.

Template

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Mark Lucking
Mark Lucking

Written by Mark Lucking

Coding for 35+ years, enjoying using and learning Swift/iOS development. Writer @ Better Programming, @The StartUp, @Mac O’Clock, Level Up Coding & More

No responses yet

Write a response