Skip to content

Commit 7691fbd

Browse files
authored
[Changelog] Add workaround for nonmutating setter
1 parent c31b184 commit 7691fbd

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,22 @@ Swift Next
6666
// This will now error, because the protocol requirement
6767
// is implicitly mutating and the setter is implicitly
6868
// nonmutating.
69-
set { someProperty = newValue }
69+
set { someProperty = newValue } // Error
7070
}
7171
}
7272
```
7373

74-
To resolve this, explicitly mark the setter as `nonmutating` in the protocol.
74+
**Workaround**: Define a new mutable property inside the setter that has a reference to `self`:
75+
76+
```swift
77+
var anotherProperty1: Int {
78+
get { return someProperty }
79+
set {
80+
var mutableSelf = self
81+
mutableSelf.someProperty = newValue // Okay
82+
}
83+
}
84+
```
7585

7686
* [SE-0253][]:
7787

0 commit comments

Comments
 (0)