[swift-evolution] Allowing mutable members in structs
Radosław Pietruszewski
radexpl at gmail.com
Fri Mar 11 05:26:47 CST 2016
> Would it make sense to allow mutable properties in structs, which could be mutated even by non-mutating methods?
This would break the whole mutability model of structs. The whole idea is: structs are always immutable, and you can mark things as “mutable”, but this can only happen if a struct is assigned to a mutable variable.
— Radek
> On 11 Mar 2016, at 11:38, Dan Raviv via swift-evolution <swift-evolution at swift.org> wrote:
>
> Would it make sense to allow mutable properties in structs, which could be mutated even by non-mutating methods?
>
> I've noticed this could be useful when implementing a non-mutating protocol method. The method semantically doesn't change the state of the protocol's implementor, and therefore shouldn't be declared as mutating. However, *some* implementations might need to change some internal state for implementing the functionality. Making specific struct properties mutable for such a case could make sense.
>
> Alternatively, Swift could allow implementing a non-mutating protocol method as a mutating method in the implementor. Currently, this doesn't seem to be allowed; Swift doesn't recognize the mutating method as a match for the non-mutating protocol method.
>
> Cheers,
> Dan
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
More information about the swift-evolution
mailing list