Join Scott Gardner for an in-depth discussion in this video Changes in Foundation, part of Swift 3 First Look.
- View Offline
- [Voiceover] Before I get into some changes in Foundation,…I'll briefly recap value types and reference types.…Value types are passed by copy,…meaning that they are copied when being assigned,…such as to a variable or passed to a function.…But actually, the copy is not made until if and when…you mutate the value.…Changes you make to a copy will not affect the original.…In our example here, if you make the change to Y…after assigning X to it, Y will be changed,…but X will remain unchanged.…
Reference types are passed by reference.…In other words, as you pass around a reference type,…what you are actually passing around is a pointer…to the same instance.…In our example, if you make a change to Y…after assigning X to it, both X and Y will see that change…because they're pointing to the same exact instance.…So, why am I reviewing this?…Well, there are 17 new or improved value types…added to Foundation.…These are all implemented as structs,…which are value types.…In many cases, these new struct value types…wrap a reference type counterpart.…
Get your first look at Swift 3 in this course with Scott Gardner. Scott demonstrates changes made to the Swift Standard Library and Cocoa and Cocoa Touch APIs and reviews the Swift API Design Guidelines, identifying key principles and best practices that will help you optimize your Swift code. Also, check out the migration case studies in chapter 3, which show how to upgrade existing projects to Swift 3.