Swift Structures are Always Pass-by-Value

Swift

I've been reading The Swift Programming Language this morning just to stay sharp, and because I've read several accounts of where Swift out performs ObjC, and the ruby-like nature of Swift means that it might be a lot faster to code up. So I was reading more...

What I found was pretty surprising about the differences between Structures and Classes - Structures are always copied when they are passed around in the code. This means that there is no way to pass-by-reference a struct to a function or method, and this will certainly modify where they can be used.

As a counter-point, in C++, classes and structs are basically the same thing. There are very minor differences, at best, and yet here in Swift, it's a fundamental difference that they chose to implement, as opposed to had to implement, and that tells me that there's something they see in Structures that they don't see for classes.

Not quite sure what that is, but immutability could certainly be one thing - passing by value allows the value(s) to be modified, but the caller's values are never touched. There might also be something in the NSPoint structures as well - something where they are looking at very simple data elements with no methods on them. Yet this means you can't have a function that modifies a passed-in structure.

Very interesting. Not sure where they are going with this, but it's something to look out for.