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
Post a Comment