[swift-evolution] Strings in Swift 4

David Sweeris davesweeris at mac.com
Fri Feb 24 17:25:59 CST 2017

> On Feb 24, 2017, at 13:41, Ted F.A. van Gaalen <tedvgiosdev at gmail.com> wrote:
> Hi David & Dave
> can you explain that in more detail?
>>> Wouldn’t that turn simple character access into a mutating function?
> assigning like   s[11…14] = str  is of course, yes.
> only then - that is if the character array thus has been changed - 
> it has to update the string in storage, yes. 
> but  str = s[n..<m]   doesn’t. mutate.
> so you’d have to maintain keep (private) a isChanged: Bool or bit.
> a checksum over the character array .  
> ?

It mutates because the String has to instantiate the Array<Character> to which you're indexing into, if it doesn't already exist. It may not make any externally visible changes, but it's still a change.

- Dave Sweeris 

More information about the swift-evolution mailing list