Skip to content

Instantly share code, notes, and snippets.

@erica
Last active March 6, 2020 02:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erica/85153085280d537f857432760cd89246 to your computer and use it in GitHub Desktop.
Save erica/85153085280d537f857432760cd89246 to your computer and use it in GitHub Desktop.
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