Michael Long
May 18, 2022

--

True, but it should be noted that if your struct contains a reference type, then passing a struct around also entails managing the reference counts on the contained object.

struct A {

let a: Int

let c: MyClass

}

You might also have mentioned that functions declared on a struct are called faster since they're dispatched statically as opposed to classes that require dynamic dispatch mechanisms due to the fact that methods on a class can be overridden.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (2)