Skip to content

Instantly share code, notes, and snippets.

@jayrhynas
Last active August 9, 2023 18:45
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 jayrhynas/76a0e37a126bd5883b044212c2a85bb9 to your computer and use it in GitHub Desktop.
Save jayrhynas/76a0e37a126bd5883b044212c2a85bb9 to your computer and use it in GitHub Desktop.
extension AttributeContainer {
init<S: AttributeScope>(_ keyPath: KeyPath<AttributeScopes, S.Type>, builder: (inout ScopedAttributeContainer<S>) -> Void) {
self.init()
builder(&self[dynamicMember: keyPath])
}
static subscript<S>(dynamicMember keyPath: KeyPath<AttributeScopes, S.Type>) -> ((inout ScopedAttributeContainer<S>) -> Void) -> AttributeContainer where S: AttributeScope {
{ AttributeContainer(keyPath, builder: $0) }
}
}
let titleAttr = AttributeContainer(\.uiKit) {
$0.foregroundColor = .black
}
let titleAttr = AttributeContainer.uiKit {
$0.foregroundColor = .black
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment