Cannot assign property in method of struct

If you want to modify the properties of the struct, mark the function as mutating.

struct Foo {
    var bar = 1

    mutating func baz() {
        bar = 2
    }
}

Leave a Comment