Swiftui Optionale Zustandsvariable -Bindung mit if letIOS

Programmierung für iOS
Anonymous
 Swiftui Optionale Zustandsvariable -Bindung mit if let

Post by Anonymous »

Der folgende Code erstellt nicht. Wie kann ich es funktionieren? < /P>

Code: Select all

import SwiftUI

struct TestView: View {

@State var model:TestModel?

var body: some View {

if let model = model {
OverlayTestView(textVM: model)
//Error: Cannot convert value of type 'TestModel' to expected argument type 'Binding'
} else {
ProgressView()
.task {
model = TestModel()
}
}

}
}

struct OverlayTestView: View {
@Binding var textVM:TestModel

var body:some View {
Text("Count \(textVM.counter)")
}
}

@Observable
class TestModel {
var counter:Int = 0
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post