Skip to content

Instantly share code, notes, and snippets.

@maximkrouk
Last active July 5, 2020 12:36
Show Gist options
  • Save maximkrouk/27dc0671a890af6eda08771a5d975316 to your computer and use it in GitHub Desktop.
Save maximkrouk/27dc0671a890af6eda08771a5d975316 to your computer and use it in GitHub Desktop.
@dynamicMemberLookup
@propertyWrapper
public <#class or struct#> <#Prefix#>Box<Content> {
public var content: Content
@inlinable
public var wrappedValue: Content {
get { content }
set { content = newValue }
}
// @inlinable
// var projectedValue: <#Type#> { <#code#> }
@inlinable
public init(wrappedValue: Content) {
self.init(wrappedValue)
}
@inlinable
public init(_ content: Content) {
self.content = content
}
@inlinable
public subscript<T>(dynamicMember keyPath: KeyPath<Content, T>) -> T {
get { content[keyPath: keyPath] }
}
@inlinable
public subscript<T>(dynamicMember keyPath: WritableKeyPath<Content, T>) -> T {
get { content[keyPath: keyPath] }
set { content[keyPath: keyPath] = newValue }
}
}
@maximkrouk
Copy link
Author

maximkrouk commented May 30, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment