Last active
March 6, 2020 02:21
-
-
Save erica/85153085280d537f857432760cd89246 to your computer and use it in GitHub Desktop.
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
import Cocoa | |
@propertyWrapper | |
public struct AssociatedValues<Value, Projection> { | |
private var value: Value | |
public var wrappedValue: Value { value } | |
public var projectedValue: [String: Projection] = [:] | |
public init(wrappedValue value: Value) { | |
self.value = value | |
} | |
} | |
public struct Test { | |
@AssociatedValues<NSView, Any> | |
public var view = NSView() | |
} | |
var t = Test() | |
print(t) | |
t.$view["weight"] = 4.2 // 4.2 | |
t.$view["weight"] // 4.2 | |
t.$view["weight"] = 5.9 // 5.9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment