Updated for Xcode 15
Structs are used almost everywhere in Swift: String
, Int
, Double
, Array
and even Bool
are all implemented as structs, and now you can recognize that a function such as isMultiple(of:)
is really a method belonging to Int
.
Let’s recap what else we learned:
struct
, giving it a name, then placing the struct’s code inside braces.mutating
.didSet
and willSet
property observers to properties inside a struct, which is helpful when we need to be sure that some code is always executed when the property changes.SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.