A follow-up to my SwiftUI rock-paper-scissors app built under deadline, working through the improvements noted at delivery. I replace array-and-int game logic with a Swift enum, consolidate separate win/loss checks into a single gameResult function returning a win/loss/draw type, and swap duplicated .hidden() views for an .opacity modifier with a ternary, cutting the view body from 74 lines to 52...
While working through Hacking With SwiftUI, I run into two points of confusion around ForEach: what the id: .self key path actually does when looping over an array of strings, and a compiler warning about non-constant ranges such as 0..<agents.count. Attempts to use key paths directly don’t compile, and a forum explanation of the warning — guarding against the array changing size during the loop — leaves me unconvinced...
My solutions to three small SwiftUI challenges: using a ternary with semantic colors to turn the total red at a 0% tip in WeSplit, wrapping the flag Image in a reusable FlagView for GuessTheFlag, and building a custom ViewModifier with a View extension that applies a large blue title style. Each solution includes a short code snippet and a link to my change on GitHub...
A SwiftUI tip on decomposing views by extracting them into custom View structs that accept values at initialization, illustrated with a reusable padded green text component. I favor this approach because such building blocks are portable and can be used in other views...
A look at how I decompose SwiftUI views into smaller pieces: storing view fragments as properties, why properties can’t reference each other, and why a computed property can’t return multiple views without a single container. I cover fixes including wrapping views in a VStack or Group or applying the @ViewBuilder attribute, and I note a quirk where omitting a VStack unexpectedly produced two preview instances...
A short SwiftUI note in which I compare two ways to vary a view based on state: branching with if/else inside the body, which Paul Hudson warns makes SwiftUI destroy and recreate views when the state changes, versus using the ternary operator within a modifier so only the changed property updates. I walk through both code versions and reflect on why the efficiency difference exists...
I give an introduction to SwiftUI views, explaining that views are immutable structs with a body property that SwiftUI renders automatically rather than being drawn manually. I cover container views like HStack and the use of modifiers such as padding and frame, including how modifiers on a container apply to its children and why their order affects the result...
This is a follow-up to my earlier simple MVVM example, correcting my use of @ObservedObject for a view model created inside a SwiftUI view. Because SwiftUI can recreate views at any time, I explain that @StateObject is the correct wrapper in that situation, with @ObservedObject reserved for objects passed down from parent views, and I link to Apple’s documentation and other explanations of the difference...
I explain the MVVM architectural pattern using a simple SwiftUI light bulb toggle app as an example. I walk through the Model, View Model, and View components, how they connect through ObservableObject and @Published/@StateObject, and why separating data from the interface matters. I’ve made the source code available on GitHub...
A short follow-up on fixing inconsistent SF Symbol heights in SwiftUI: locking the symbol height inside a frame solves the earlier problem, but breaks down when users change their text size. Apple’s @ScaledMetric property wrapper, introduced in iOS 14, scales the value with Dynamic Type and addresses that, though I admit not fully understanding how it works...
A short note on finally understanding SwiftUI’s declarative nature after watching a 2019 WWDC video on the topic. I still have unanswered questions about how views bind to their data, plan to watch the series’ Data Flow video next, and acknowledge the detour is a way of procrastinating from two ongoing courses...
After hearing Dave Verwer’s iOS Dev Weekly newsletter mentioned on a podcast, I subscribed and describe my first issue as short, chatty, and full of useful links on Swift libraries and other topics. Following a link about SwiftUI Split View Configuration led me down a rabbit hole to a WWDC video...
Impressions of a free compilation video from Sean Allen’s SwiftUI fundamentals course, which I find strong on explaining child views and layout stacks but note assumes existing Swift language knowledge. The later lessons on passing values into views speak to my own confusion about SwiftUI app structure and how views get redrawn, making the paid course tempting despite my already juggling several other learning resources...