variable5.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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