blog.iankulin.com

Possibly-Useful

Regex to split a string with two different characters

A walkthrough of using Swift 5.7’s regex support as the separator argument to String.split(), in order to parse a string like “Some behaviour (expectation)” into its two parts. I build the expression up step by step, covering escaping of brackets and spaces and the use of the pipe for OR, and note that the Playgrounds app doesn’t yet support Swift 5.7...

Copying a file via SSH

I copy a sample JSON file from my Mac to a Raspberry Pi on the home network using the scp command, after noting that drag-and-drop into an SSH session isn’t possible. I include the basic command syntax with a brief explanation of its arguments...

Mock Data

Needing mock student data for an iOS app without using real records, I try Mockaroo, a web-based test data generator with configurable field types and download options including JSON and a REST API. My writeup ends with a privacy caution that schemas saved on the service are publicly visible...

iOS 16 Developer Mode

After updating my iPhone to iOS 16, I found my app would no longer run until Developer Mode was enabled. I briefly cover where to find the setting (in Privacy and Security) and note that it requires a reboot and re-authentication...

git stash

I take a short look at using git stash to temporarily set aside uncommitted changes and revert a directory to the last commit, then git stash pop to restore them — handy for grabbing an earlier version of code. I also briefly mention more advanced stash features like naming, multiple stashes, and viewing diffs, with a link to Atlassian’s guide...

git - Rollback to last commit

While following a type-along tutorial in the 100 Days of SwiftUI course, I commit the setup code once it’s working, then use git reset –hard to discard each technique’s changes before moving to the next one. I include the handful of git commands involved, suggesting this simple rollback workflow is a good first use case for anyone new to git...

@Binding - data between views

I explain SwiftUI’s @Binding property wrapper, framed by an analogy to passing pointers in C. A short code example demonstrates a parent view passing an @State variable to a subview with the $ prefix, letting the subview read and mutate the value...

Codable when the keys don't match

How to decode JSON in Swift when the key names don’t match your struct’s property names. I cover using a CodingKeys enum to map JSON keys to properties manually, and the simpler keyDecodingStrategy option for handling the common snake_case versus camelCase mismatch...

Codable & JSON

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

Refreshing SwiftUI Views

Ways to force a SwiftUI view to redraw, demonstrated with a sample app that tracks a list of cars and their counts. The core technique is toggling a @State property that gets passed into subviews, which I then trigger via pull-to-refresh with .refreshable(), on app activation by watching scenePhase with .onChange, and on an interval with a published Timer and .onReceive...

Using Swift's map

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

SwiftLint

Prompted by a video on effective developer habits, I finally add a linter to my Swift workflow. I cover installing SwiftLint and hooking it into Xcode builds, adjusting rules via a swiftlint.yml config file, and selectively disabling rules with code comments. My approach is to enable all optional rules up front, then decide for each violation whether to change the code or drop the rule...

Testing, testing

A walkthrough of adding unit tests to an existing Swift project in Xcode, using my CodeTrimmer macOS utility as the example. I cover adding a unit testing target, writing XCTest functions for the stripSpaces() method, and running the tests to see the results...

Where's My App?

My short guide to building a release version of a macOS app in Xcode and finding the resulting .app bundle. I cover creating a new scheme set to Release builds, running the build, and using “Show Build Folder in Finder” to locate the .app file so it can be copied into the Applications folder...

Customizing the default About dialog for MacOS apps

A short how-to on how I customize the default About dialog in a macOS app built with Xcode: add a Credits.rtf (or .html or .rtfd) file to the project, and its contents appear in the dialog after a rebuild...

Gitting Xcode to Push

I explain how to fix Xcode failing to push to GitHub after GitHub stopped accepting RSA keys that use SHA-1. My solution, based on an Apple Developer forum answer, is to switch to a new ECDSA SSH key — with the one step the forum post missed being a restart of Xcode to make it take effect...

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

Simple MVVM

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

Gitting the hang of it

A beginner-oriented cheat sheet I put together for using git from the command line on macOS, aimed at people working with Xcode and GitHub. I walk through setting up a new repository and pushing it to GitHub, then cover basic commands for status, add, commit, push, and tagging, along with .gitignore notes and cloning from a tag. I include a short list of git learning resources at the end...