• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: More Swift issues, NSURLComponents
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: More Swift issues, NSURLComponents
      • From: Rick Mann <email@hidden>
References: 
 >More Swift issues, NSURLComponents (From: Rick Mann <email@hidden>)
 >Re: More Swift issues, NSURLComponents (From: Jens Alfke <email@hidden>)
 >Re: More Swift issues, NSURLComponents (From: Rick Mann <email@hidden>)
 >Re: More Swift issues, NSURLComponents (From: Charles Srstka <email@hidden>)
 >Re: More Swift issues, NSURLComponents (From: Rick Mann <email@hidden>)
 >Re: More Swift issues, NSURLComponents (From: Jens Alfke <email@hidden>)
 >Re: More Swift issues, NSURLComponents (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: More Swift issues, NSURLComponents
  • Next by Date: Re: More Swift issues, NSURLComponents
  • Previous by thread: Re: More Swift issues, NSURLComponents
  • Next by thread: Re: More Swift issues, NSURLComponents
  • Index(es):
    • Date
    • Thread