swift mutating 作用
在 Swift 中，structure ??enumeration 被創建之后其值和屬性不可變的，如果你需要在一個修改屬性值，需要給這個方法添加 mutating 特性。
“Structures and enumerations are value types. By default, the properties of a value type cannot be modified from within its instance methods.
However, if you need to modify the properties of your structure or enumeration within a particular method, you can opt in to mutating behavior for that method. The method can then mutate (that is, change) its properties from within the method, and any changes that it makes are written back to the original structure when the method ends. The method can also assign a completely new instance to its implicit self property, and this new instance will replace the existing one when the method ends.
You can opt in to this behavior by placing the mutating keyword before the func keyword for that method:”
Excerpt From: Apple Inc. “The Swift Programming Language (Swift 3).” iBooks.?
在上面例子中，setName 方法需要修改 immutable 屬性 name，所以前面要加上 mutating。