blog.iankulin.com

Posts

Day 23 - Views and Modifiers - Part 3

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...

Day 23 - Views and Modifiers - Part 2

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...

Day 23 - Views and Modifiers - Part 1

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...

Project 2 - Guess the Flag

The second tutorial project in my 100 Days series, a flag-guessing game written with everything in the view — an approach I grew uneasy with as the challenges expanded it. Takeaways include string-based image asset identification, alert dialogs in a declarative framework, and gradients and frosted glass effects. Source code is on GitHub...

Download a Directory from a GitHub Repo

While working through the 100 Days of SwiftUI, I needed to download a single directory of flag images from a GitHub repo, but found that neither git nor GitHub’s web interface offers a simple way to do that. In this post, I cover a workaround using GitHub’s web-based VSCode: change github.com to github.dev in the repo URL, then right-click the folder to download it...

Challenge 1

I built a simple unit conversion app for Challenge 1 of Day 19 of 100 Days of SwiftUI, deliberately keeping it minimal without MVVM. New techniques I covered include limiting the keyboard to numbers and adding a toolbar to dismiss it. I also note that SwiftUI text fields don’t select existing text for overtyping, with no straightforward fix short of a third-party package, and I include full code plus a GitHub link...

$==Commitment

I cover Paul Hudson’s free 100 Days of SwiftUI course and the paid Hacking with Swift+ subscription option. I signed up for a year to support Hudson’s contributions to the Swift community and because the one-year time limit makes it more likely I will complete the course...

Int.times()

I propose adding a times method to Int via an extension, allowing a closure to run a set number of times, in a follow-up to a post about discarding loop variables with an underscore. I find the same idea was already shared as a Stack Overflow answer seven years earlier. I also consider a hypothetical for each in loop syntax, along with why it would likely break existing code...

The _ Underscore

I cover two uses of the underscore in Swift: omitting a parameter’s external name in function calls, and standing in for an unused loop variable when iterating over a collection. I also question whether the loop usage reads well, floating the idea of a reserved word like “each” instead, and note that forEach raises the same naming issue...

Unwrap App

My review of Unwrap, Paul Hudson’s iOS app for learning Swift, which pairs short videos and written lessons with true-or-false questions about Swift code. Though the quizzes sometimes test error-spotting rather than the specific lesson topic, I found they sharpened both my syntax knowledge and my ability to spot mistakes in code. The app is a good way to use spare moments on a phone, even for those not following the Hacking with Swift courses...

Codewars / reduce

Trying out Codewars, I solve a beginner Swift kata about finding the integer that appears an odd number of times in an array, using a Set to track entries. The top community solution turns out to be a one-liner using reduce and XOR, prompting me to explain how reduce works, why XORing every element leaves the odd-occurring value, and to argue that the longer version is still easier to read...

Sometimes the Gold is in the Comments

A SwiftUI tutorial video on @ObservedObject versus @StateObject turns out to be outdated, referencing older APIs like @ObjectBinding and Combine. The experience prompts me to reflect on how technical content should signal its age, such as through version tags, so future readers can judge whether it’s still relevant...

Playgrounds are good

After needing to run small C and C++ snippets and missing Swift Playgrounds, I look at options for scratch coding on an iPad. A C Language app works via an online compiler but feels sluggish, and some paid apps advertised as offline compilation actually send code to a server. Free online compilers that support many languages, including C and Swift, turned out to be a handy alternative...

Named Loops

Breaking out of nested loops to a specific outer loop has no direct support in C/C++, so the traditional workaround is converting for loops to while loops with a continue flag, which I demonstrate with an example that stops processing a string at a given character. Swift offers a cleaner alternative through labeled loops, where naming a loop lets a break statement exit directly to that level...

Checkpoint 9

My solution to Hacking with Swift’s Checkpoint 9: writing a single-line Swift function that returns a random element from an optional integer array, or a random number from 1 to 100 when the array is nil or empty. I show the challenge, an embedded video, and the finished one-liner...

Visual Studio Code

A short review of Visual Studio Code after trying it for HTML/CSS and C++ work on a Mac. I found the experience smooth across the board, praising the painless extension setup, code completion, debugging with breakpoints, and git integration, though Xcode remains my IDE of choice...

CSS Intro

My HTML experience ends in 1996, before CSS existed, so I am catching up on the basics. I share and recommend a Tech With Tim video introducing CSS for non-web developers, embedded in the post...

Checkpoint 8

My solution to Hacking with Swift’s Checkpoint 8: a Building protocol requiring rooms, cost, and estate agent properties, with a protocol extension providing a method that prints a sales summary. My House and Office structs conform to the protocol, each adding its own extra property, and my sample instances show the method in use...

Protocols

Swift structs can’t use inheritance and classes are limited to a single superclass, so protocols fill the gap by letting structs, classes, and enums adopt shared properties and methods. I walk through a C++ multiple inheritance example and its Swift protocol equivalent, showing how a function can accept any type that conforms to a given protocol...

Checkpoint 7

My solution to Hacking with Swift’s Checkpoint 7, which calls for an animal class hierarchy with Animal, Dog, and Cat as superclasses and specific breeds as subclasses. My included Swift code implements the legs property, overridden speak() methods for each breed, and an isTame property set through initializers...