3 ms·
> According to the Swift language guide Strings, Arrays, and Dictionaries are all copied on assignment to a variable. This might've been a recent change in doc
by goblin89 12y ago
> According to the Swift language guide Strings, Arrays, and Dictionaries are all copied on assignment to a variable.
This might've been a recent change in docs. Quoting part of the same section from my copy of the Swift book downloaded a while ago (emphasis mine):
‘The assignment and copy behavior for Swift’s Array type is more complex than for its Dictionary type…
‘If you assign an Array instance to a constant or variable, or pass an Array instance as an argument to a function or method call, the contents of the array are not copied at the point that the assignment or call takes place. Instead, both arrays share the same sequence of element values. When you modify an element value through one array, the result is observable through the other.
‘For arrays, copying only takes place when you perform an action that has the potential to modify the length of the array.’
As an aside, it would be nice if Apple offered some kind of change log or a “what's changed” page for Swift docs (though to my knowledge they had made no promises regarding spec stability yet).
- josephlord 12y agoRevision history for the main Swift book: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/RevisionHistory.html https://developer.apple.com/library/prerelease/ios/documenta... Note that you have to delete the book in iBooks and download it again to get the new version.