Join Scott Gardner for an in-depth discussion in this video Mutating methods, part of Swift 3 Essential Training: Beyond the Basics.
- [Instructor] By default, methods of a structure…cannot change the structure itself,…or it's property values.…I'm started out with a beginning implementation…of a Counter structure.…It has a total property set to zero by default.…And I've created an instance of Counter,…I want to be able to increment this Counter.…So, I'll define an increment method…that will increment total by the amount pass,…with a default value of one,…and it will return itself.…
I'm getting an error…that self is not mutable.…With a fix-it suggestion to mark the method as mutating,…which I'll select to do.…Now I can call increment on Counter…without passing any value…and it's total will be increased by one.…Or, I can pass a value to increment by…and it will be increased by that amount.…You might be wondering if…since increment returns the Counter instance,…you can chain multiple calls…to a mutating method, such as increment.…
This produces an error.…Cannot use mutating member on immutable value;…function call returns an immutable value,…even though I defined Counter as a variable.…
- Adding source files, resources, links, and literals
- Adding pages to a playground
- Using overflow operators and bitwise operators
- Using ranges with strings
- Creating complex sequences
- Chaining higher-order functions
- Defining lazy properties
- Using failable initializers
- Mutating methods
- Working with singletons
- Nesting function types
- Creating error types and recursive enumerations
- Extending concrete types
- Referencing selectors and key paths
- Working with protocol-oriented programming
- Defining class-only protocols and optional protocols
- Using option sets, type checking, and casting operators
Skill Level Intermediate
Core Data for iOS and macOS Enterprise Developerswith Jon Bott1h 46m Intermediate
Distributing Your iOS App for Testing with TestFlightwith Ron Buencamino35m 10s Intermediate
iOS App Development: Test-Driven Developmentwith Harrison Ferrone2h 14m Intermediate
3. Strings and Characters
4. Sequences and Collections
5. Control Flow
6. Value and Reference Types
9. Access Control
Understand access control3m 47s
Next steps1m 2s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.