Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created April 5, 2023 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/4ee9eadeb0c8f9b37e8a80dcd9de5eb9 to your computer and use it in GitHub Desktop.
Save sturdysturge/4ee9eadeb0c8f9b37e8a80dcd9de5eb9 to your computer and use it in GitHub Desktop.
import SwiftUI
#if hasAttribute(dynamicMemberLookup)
@dynamicMemberLookup
struct Print {
static subscript(dynamicMember member: String) -> String {
print(member)
return member
}
}
struct ContentView: View {
@State var input = ""
@State var output = ""
var body: some View {
Form {
Button("Print") {
output = Print.helloWorld
}
Text(output)
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment