The guidance for using structs in Swift is very straightforward:
- Use structures by default.
- Use classes when you need Objective-C interoperability.
- Use classes when you need to control the identity of the data you're modeling.
- Use structures along with protocols to adopt behavior by sharing implementations.
It's nice that it's so straightforward, but it made me wonder if Swift is doing any sort of optimizations under the hood in scenarios where it would be more performant to pass a reference to a function as opposed to a large struct (copy-on-write comes to mind).