I want to pass a value to a property marked with @State, and it doesn't work.
struct AView: View {
@State private var content: String?
var body: some View {
Text(content ? "")
}
init(content: String) {
self.content = content
}
}
#Preview {
AView(content: "Test")
}
But if I change the content to non optional, it works well.
struct AView: View {
@State private var content: String
var body: some View {
Text(content)
}
init(content: String) {
self.content = content
}
}
#Preview {
AView(content: "Test")
}
I googled for a while and found that I need to use a spacial way to initialize @State property in the first case.
init(content: String) {
_content = State(initialValue: content)
}
It works, but why? Is there any difficulty to unified API between optional and non optional @State property?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
My project uses a local swift package of my own, which uses SwiftGenPlugin to generate image resources. I can archive the project locally, but Xcode Cloud doesn't work and reports an error: "SwiftGenPlugin" is disabled.