Cannot assign to property: function call returns immutable value

后端 未结 3 1640
长情又很酷
长情又很酷 2020-12-11 03:15

Consider the following example.

struct AStruct{
    var i = 0
}

class AClass{
    var i = 0
    var a: A = A(i: 8)

    func aStruct() -> AStruct{
              


        
3条回答
  •  情话喂你
    2020-12-11 03:53

    Try using a class instead of a struct, as it's passed by reference and holds onto the object, while a struct is passed by value (a copy is created).

提交回复
热议问题