Skip to content

Instantly share code, notes, and snippets.

@wizard1066
Created October 5, 2020 16:17
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 wizard1066/47b1b32784a6b33473f794ed891c2680 to your computer and use it in GitHub Desktop.
Save wizard1066/47b1b32784a6b33473f794ed891c2680 to your computer and use it in GitHub Desktop.
variable5.swift
struct ContentView: View {
var body: some View {
SwiftUIViewF()
.onTapGesture {
Greeting.shared.words = "Hello, World!"
}
}
}
final class Greeting: ObservableObject {
@Published var words = "X"
static var shared = Greeting()
}
struct SwiftUIViewF: View {
@ObservedObject var meet = Greeting.shared
var body: some View {
Text(meet.words)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment