swift - Cannot assign property in method of struct -


in swift, i'm trying following:

struct foo {     var bar = 1      func baz() {         bar = 2     } } 

xcode reports error cannot assign 'bar' in self on line in method.

why? if change struct class, there's no error.

if want modify properties of struct, mark function mutating.

struct foo {     var bar = 1      mutating func baz() {         bar = 2     } } 

Comments

Popular posts from this blog

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -