Created
May 29, 2022 02:51
-
-
Save 0si43/9e4aa041bdeaef62846aafa87d1e8d06 to your computer and use it in GitHub Desktop.
@Stateの挙動を調べた
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 FailureView: View { | |
@State var isShowSheet = false | |
@State var shareData: String? | |
var body: some View { | |
Button("Change(Fail)") { | |
shareData = "Show this message" | |
isShowSheet = true | |
} | |
.sheet(isPresented: $isShowSheet) { | |
Text("Passed data: " + (shareData ?? "")) | |
} | |
} | |
} | |
struct FailureView_Previews: PreviewProvider { | |
static var previews: some View { | |
FailureView() | |
} | |
} |
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 | |
@main | |
struct SampleApp: App { | |
var body: some Scene { | |
WindowGroup { | |
FailureView() | |
SuccessView() | |
} | |
} | |
} |
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 SuccessView: View { | |
@State var shareItem: ShareItem? | |
var body: some View { | |
Button("Change(Success)") { | |
shareItem = ShareItem(data: "Show this message") | |
} | |
.sheet(item: $shareItem) { item in | |
Text("Passed data: " + item.data) | |
} | |
} | |
} | |
struct ShareItem: Identifiable { | |
var id = UUID() | |
var data: String | |
} | |
struct SuccessView_Previews: PreviewProvider { | |
static var previews: some View { | |
SuccessView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment