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

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -