使用其他属性初始化@Binding 时出现问题

Issues when initialising @Binding with other properties

无法初始化 属性 和 @Binding 对象

我也试过在 struct

的 init( ) 方法中初始化它
struct WorkoutCard: View {

       var numberOfWorkouts : [Int] = [0, 1, 2, 3]

       @State var beginWorkout :Bool = false

 var body: some View {
        ZStack {

       Rectangle().foregroundColor(Color.black)

            if !self.beginWorkout {

    ScrollView (.horizontal, showsIndicators: false) {

         HStack {


   ForEach(self.numberOfWorkouts.reversed(), id: \.self) { index in


           Card(index, beginWorkout: $beginWorkout)


            }
 }

                } }
          }
}


 }

// 待初始化的视图

 struct Card: View {

var number : Int

@Binding var beginWorkout : Bool


    init(_ index: Int) {
        self.number = index
          }
  }

错误 = 调用中的额外参数 "beginWorkout"

在你的通话中,你错过了.self

Card(index, beginWorkout: self.$beginWorkout)

并且您的初始化器缺少 beginWorkout 参数:

struct Card: View {

    var number : Int

    @Binding var beginWorkout : Bool

    init(_ index: Int, beginWorkout: Binding<Bool>) {
        self.number = index
        self._beginWorkout = beginWorkout
    }

    var body: some View {
        ...
    }
}