November 2016
Intermediate to advanced
480 pages
14h 42m
English
After working through this chapter, you might be wondering about the mutating keyword.
Why is it needed to allow you to modify a struct or enum?
A useful place to start is to revisit functions that return functions.
Create a new playground called Mutating. Add a simple function to your playground that returns a String greeting.
Listing 15.16 A simple greeting function
func greet(name: String, withGreeting greeting: String) -> String {
return "\(greeting) \(name)"
}
The greet(name:withGreeting:) function takes two arguments: a name and a greeting. It constructs and returns a greeting based on these two arguments. This function is straightforward to use.
Listing 15.17 Using greet(name:withGreeting:) ...
Read now
Unlock full access