Last active
June 7, 2019 17:18
-
-
Save sidepelican/fd88b37c68915caa7580a11eb8a94f0e to your computer and use it in GitHub Desktop.
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
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