Skip to content

Instantly share code, notes, and snippets.

@sidepelican
Last active June 7, 2019 17:18
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 sidepelican/fd88b37c68915caa7580a11eb8a94f0e to your computer and use it in GitHub Desktop.
Save sidepelican/fd88b37c68915caa7580a11eb8a94f0e to your computer and use it in GitHub Desktop.
import SwiftUI
struct MyNumber: View {
private let value: Int
init() {
print(#function, #line)
value = 1000
}
init(_ v: Int) {
print(#function, #line)
value = v
}
var body: some View {
Text("\(value)")
}
}
struct ContentView : View {
@State var something: Int = 0
var body: some View {
return VStack {
if Bool.random() {
MyNumber()
} else {
MyNumber(something)
}
Button(action: {
self.something = Int.random(in: 0...100)
}) {
Text("Push")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment