Created
July 21, 2019 06:18
-
-
Save mortenbekditlevsen/078d4ae3cd935d9e743ba51a1ac2b019 to your computer and use it in GitHub Desktop.
PropertyWrapper nesting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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