mutating method swift simple example – how to write ?

By | August 4, 2016

mutating method swift simple example – how to write ?

Structure and enumeration are value type in swift. That means an instance method can not change its properties. For example a method within structure cannot change any variable defined within structure. To do so you need a method that is mutating – means changing the property or being able to change a property value.

Cannot use mutating member on immutable value – such error will arise if you would have instance with let keyword and try to call mutating function with it. Use var istead