Skip to content

Instantly share code, notes, and snippets.

@mortenbekditlevsen
Created July 21, 2019 06:18
Show Gist options
  • Save mortenbekditlevsen/078d4ae3cd935d9e743ba51a1ac2b019 to your computer and use it in GitHub Desktop.
Save mortenbekditlevsen/078d4ae3cd935d9e743ba51a1ac2b019 to your computer and use it in GitHub Desktop.
PropertyWrapper nesting
@propertyWrapper
struct A<T> {
private var _storage: T
var wrappedValue: T {
get { _storage }
mutating set { _storage = newValue }
}
}
@propertyWrapper
class B<T> {
private var _storage: T
var wrappedValue: T {
get { _storage }
set { _storage = newValue }
}
init(_ t: T) {
self._storage = t
}
}
struct DontMutateMe {
@A @B var c: Int
func doesNotMutate() {
// c = 1
_c.wrappedValue.wrappedValue = 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment