blog.iankulin.com

Checkpoint

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

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

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

Checkpoint 6

My short Swift exercise solution covers structs and access control: a Car struct stores a model, seat count, and current gear. The gear is protected with private(set) access and can only be changed through my mutating gearUp and gearDown methods that stay within static min and max gear constants...

Checkpoint 5

My Swift solution to an array-processing exercise: filtering even numbers out of an array of lucky numbers, sorting the remaining values in ascending order, mapping each one to a formatted string, and printing the results one per line using filter, sorted, and map...

Checkpoint 4

My Swift solution to a coding challenge: compute the integer square root of a number between 1 and 10,000 without using the built-in sqrt() function. My implementation uses a brute-force loop and throws custom errors for out-of-bounds input or when no integer root exists, with do/catch error handling shown in the example usage...

Checkpoint 4 optimisation

A walkthrough of the Hacking with Swift Checkpoint 4 exercise, computing integer square roots in Swift. I first solve it with a brute-force loop, then show a binary search version that handles far larger input ranges with no perceptible delay, and reflect on the trade-offs between code simplicity and performance...

Checkpoint 3

This is my Swift implementation of the classic FizzBuzz exercise. My code loops from 1 to 100, using named booleans for divisibility by 3 and 5 to decide whether to print Fizz, Buzz, FizzBuzz, or the number itself...