Re: More Swift issues, NSURLComponents
Re: More Swift issues, NSURLComponents
- Subject: Re: More Swift issues, NSURLComponents
- From: Jens Alfke <email@hidden>
- Date: Mon, 12 Oct 2015 14:08:12 -0700
> On Oct 12, 2015, at 2:00 PM, Rick Mann <email@hidden> 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.
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
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden