Mutability and Foundation value types
One of the key concepts of the Swift language is to give developers the ability to control the mutability of their objects. We use let
to make a value a constant and var
to make the value a variable. However, certain types, when imported from Objective-C, do not provide easy mutability features. Swift 3 aims to change this by adding a new set of Foundation value types to wrap reference types in order to provide mutable options for developers. In fact, this really isn't all that new as Foundation already uses many value types in both Objective-C and Swift. Foundation has existing types such as primitives, Enumerations, Option sets, and C structure types that already were value types in previous versions of Swift and Objective-C.
To make the conversion from reference type to value type possible, Swift uses the copy-on-write technique for new value types whose underlying data contains more than just simple data. With copy-on-write, the value type represents...