Michael Long
Feb 11, 2024

--

Really wish you'd do individual articles rather than dumps of often non-related concepts.

1) ForEach is best used when the closure is self contained. Referencing self or external variables in the closure requires capturing those references.

3) The biggest advantage to map isn't mentioned, in that map creates a destination array of equivalent size in which to store the results, whereas the empty array/append method will in all likelihood require the array to reallocate and resize several times as elements are added.

5) Yes. Sort of. Kind of. The example is clear, but can be complicated when the struct contains reference types like strings or arrays (buffer backed entries that are reference counted). And more so if the struct is conforms to some protocol that uses witness tables under the hood.

--

--

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 (1)