You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's sort of correct. :-/ The problem is that mutating methods implemented in protocol extensions are allowed to re-assign self, which is something that doesn't exactly make sense for a class: it will reassign the reference, but not change any other references. There's a whole family of issues that show that protocols with mutating methods produce surprising and potentially-bug-prone results with classes.
You can work around this by using a temporary var:
var mutableSelfHack = self
mutableSelfHack.restoreState()
but you may want to reconsider whether it makes sense for a class to conform to a protocol with mutating methods at all.
Additional Detail from JIRA
md5: 89dcbdfbbd2ca57390d28d060b60ed39
duplicates:
var
declaration of class variablesIssue Description:
Is this error correct? If yes, how to work around it because mutating doesn't work on classes
The text was updated successfully, but these errors were encountered: