As an iOS developer a week into learning JavaScript, I reflect on what I miss from Swift, including the determinism of compiled code, a complete IDE for debugging, and the ability to fully remove deprecated language features. I also cover what JavaScript has in its favour, such as its low barrier to entry and lack of a required build step...
In this beginner-level look at Swift’s Codable protocol, I explain that it combines Encodable and Decodable and is applied automatically when a type’s properties are all Codable. I use simple code examples to demonstrate encoding a struct to JSON with JSONEncoder and decoding JSON back into a struct with JSONDecoder. I flag more involved cases, such as decoding JSON with snake_case keys, as topics for later posts...
My solutions to the three wrap-up challenges for the Moonshot app from the 100 Days of SwiftUI course, an information app about the Apollo missions. My work covers displaying formatted launch dates, extracting the crew view and a custom divider into separate structs, and adding a toolbar toggle between grid and list mission layouts, with some notes on the tradeoffs of splitting views out...
While working through Day 39 of the Hacking with Swift 100 Days of SwiftUI course, I explain Swift’s map method, which applies a closure to each element of a collection and returns a transformed array. Simple Playground examples demonstrate mapping integers to strings, with equivalent forEach and for loop versions included for comparison...
A follow-up to my previous post about the difference between writing a SwiftUI ForEach range as 1..<21 versus 1…20. I found the answer in a Hacking with Swift Day 34 article, which indicates older versions of Swift might not have allowed the closed-range form...
A short note on updating to Xcode 14 and Swift 5.7: the update is found in the Mac App Store rather than Xcode’s About dialog. I also show how to check your current Xcode and Swift versions, both through Xcode’s project settings and via the command line, and link elsewhere for details on what’s new in each release...
In refactoring my rock-paper-scissors project, I replace Int-based hand shape values with a Swift String enum, eliminating the risk of array out-of-bounds errors and allowing switch statements without a default case. I include notes on Swift enums compared to C, enum methods, and my uncertainty about naming the type Shape versus FingerShape...
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...
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...
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...
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...
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...
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...
Prompted by buzz around Carbon and Rust’s frequent appearances in conversation, I, a developer with a Swift background, take a first look at Rust through a video and a couple of articles. I compare Rust’s features — optionals, type inference, exhaustive match statements, immutability, traits, and closures — against their Swift counterparts, concluding that Rust feels familiar but less readable than Swift...
My reflections on a Lex Fridman interview with Chris Lattner, main author of Swift, touching on value versus reference types and how languages deliver their complexity — illustrated with a comparison of hello world in Swift versus C++. I come away convinced Swift plus Playgrounds is a good introduction to programming for kids, with more reservations about SwiftUI...
I explain Swift memory management, starting with the difference between value types and reference types and why the latter requires Automatic Reference Counting. My code examples using a class with init and deinit methods show ARC working as expected, then demonstrate a retain cycle where two objects reference each other and are never deallocated...
Working through the Swift book, I cover functions as first-class types and passing closures around, then grapple with how closures capture variables that persist after their original scope has ended. My code examples show nested functions and a makeIncrementer closure, along with my reservations about variable capture and my suspicion that ARC is what keeps captured variables alive...
While working through cs193p homework, I praise the Swift book’s clear, step-by-step explanation of closures, and by coincidence encounter the same topic twice more that day in a Fireside Swift podcast episode and an iOS Academy video. The post also notes that closures can be challenging without experience passing around function pointers or doing multithreaded programming, and that Swift’s ability to cut the syntax down to very little takes getting used to...
My notes on day 10 of the 100 Days of SwiftUI course, which covers structs. Having worked in languages where structs are just data containers, I find their methods and properties initially confusing — including a now-resolved question about the purpose of tuples — and demonstrate with sample code how structs are copied as value types while classes are passed by reference. I also note that SwiftUI sample code is built entirely from structs...
A short follow-up in which I note an unexpected benefit of watching CS193P lecture videos: learning how terms are actually pronounced. I had always said “tuple” to rhyme with “cup,” but the videos revealed the correct pronunciation is “too-pull.”..