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

php - How to modify a menu to show sub-menus -

shopping cart - Page redirect not working PHP -

python - Installing PyDev in eclipse is failed -