Trevor Whittingham 6/29/2026

Stop Treating Size Class As Screen Width In SwiftUI

Read Original

This article discusses the pitfalls of using `@Environment(\.horizontalSizeClass)` as a shortcut for determining screen width in SwiftUI, particularly in light of iOS apps becoming resizable for larger displays, iPad, and iPhone Mirroring on Mac. It argues that size class is a trait, not a measure of actual view width, and provides examples of how branching on size class can lead to incorrect layouts. The post offers alternatives like GeometryReader, ViewThatFits, and NavigationSplitView, and includes a code example of a mailbox-style UI that needs auditing. It emphasizes using available size of the surrounding view for finer control, referencing WWDC26 sessions and Xcode 27 features.

Stop Treating Size Class As Screen Width In SwiftUI

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week

No top articles yet