> On Oct 12, 2015, at 14:08 , Jens Alfke <[email protected]> wrote: > > >> On Oct 12, 2015, at 2:00 PM, Rick Mann <[email protected]> wrote: >> >> In all this discussion, I forgot to bring up the containers: are they >> special? A "let" container can't be reassigned, nor can its contents be >> changed. How is this implemented? > > No, they’re not special, but they’re structs (not classes). That means > they’re passed by value (copied), and their methods can be marked ‘mutable’ > to indicate that they modify the object.
Oh! I thought they were classes. Thanks. > Under the hood, as an optimization, the collection classes use copy-on-write > indirection — an Array struct just contains a pointer to an internal buffer > (a class instance) that has the actual data. That makes copying an Array > efficient. The implementation just has to be careful to allocate a new buffer > before modifying the contents, if the buffer is shared with any other Arrays. > (There are some low-level public Swift types that act as helpers for > implementing this pattern.) > > If you want to know lots more, read Mike Ash’s article “Let’s Build Swift > Array”: > > https://www.mikeash.com/pyblog/friday-qa-2015-04-17-lets-build-swiftarray.html > Thanks! -- Rick Mann [email protected] _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
