Binding 无法转换类型为';Int?&x27;到预期的参数类型';装订<;Int>';迅捷

Binding 无法转换类型为';Int?&x27;到预期的参数类型';装订<;Int>';迅捷,binding,swiftui,Binding,Swiftui,我创建了一个circularprogress视图,以便能够根据步骤数据显示进度条。但由于某些原因,我无法访问stepView文件中的step.count 这是我的StepView struct StepView: View { private var healthStore: HealthStore? @State private var presentClipboardView = true @State private var step

我创建了一个circularprogress视图,以便能够根据步骤数据显示进度条。但由于某些原因,我无法访问stepView文件中的step.count

这是我的StepView

    struct StepView: View {
        private var healthStore: HealthStore?
        @State private var presentClipboardView = true
        @State private var steps: [Step] = [Step]()
        init() {
            healthStore = HealthStore()
        }
        private func updateUIFromStatistics(_ statisticsCollection: HKStatisticsCollection) {
            let now = Date()
            let startOfDay = Calendar.current.startOfDay(for: now)
            statisticsCollection.enumerateStatistics(from: startOfDay, to: now) { (statistics, stop) in
                let count = statistics.sumQuantity()?.doubleValue(for: .count())
                let step = Step(count: Int(count ?? 0), date: statistics.startDate, wc: Double(count ?? 0 / 1000 ))
                steps.append(step)
            }
        }
        var body: some View {  
            VStack {
                ForEach(steps, id: \.id) { step in
                    VStack {
                            HStack{
                                Text("WC")
                                Text("\(step.wc)")
                            }
                            HStack {
                                Text("\(step.count ?? 0)")
                                Text("Total Steps")
                            }
                            Text(step.date, style: .date)
                                .opacity(0.5)
                        CircularProgress(steps: step.count) //ERROR
                            Spacer()
                    }
                }
                .navigationBarBackButtonHidden(true)
                
            }
            
            .onAppear() {
                if let healthStore = healthStore {
                    healthStore.requestAuthorization { (success) in
                        if success {
                            healthStore.calculateSteps { (statisticsCollection) in
                                if let statisticsCollection = statisticsCollection {
                                    updateUIFromStatistics(statisticsCollection)
                                }
                            }
                        }
                    }
                }
            }
            .onDisappear() {
                self.presentClipboardView.toggle()
            }
        }
    }
这是我的circularprogress观点

    struct CircularProgress: View {
    var steps: Binding<Int>
    var body: some View {
        ZStack {
            Color.progressBarColor
                .edgesIgnoringSafeArea(.all)
            VStack {
                ZStack {
                    Label()
                    Outline(steps: steps)
                }
            }
        }
    }
}

struct Label: View {
    var percentage: CGFloat = 20
    var body : some View {
        ZStack {
            Text(String(format: "%.0f", percentage))
                .font(Font.custom("SFCompactDisplay-Bold", size: 56))
        }
    }
}

struct Outline: View {
    var steps: Binding<Int>
    var percentage: CGFloat = 20
    var colors : [Color] = [Color.trackProgressBarColor]
    var body: some View {
        ZStack {
            Circle()
                .fill(Color.clear)
                .frame(width: 250, height: 250)
                .overlay(
                    Circle()
                        .trim(from: 0, to: percentage * 0.01)
                        .stroke(style: StrokeStyle(lineWidth: 20, lineCap: .round, lineJoin: .round))
                        .fill(AngularGradient(gradient: .init(colors: colors), center: .center, startAngle: .zero, endAngle: .init(degrees: 360)))
                ).animation(.spring(response: 2.0, dampingFraction: 1.0, blendDuration: 1.0))
        }
    }
}
struct CircularProgress:视图{
var步骤:绑定
var body:一些观点{
ZStack{
颜色
.edgesIgnoringSafeArea(.all)
VStack{
ZStack{
标签()
大纲(步骤:步骤)
}
}
}
}
}
结构标签:视图{
风险值百分比:CGFloat=20
var body:一些观点{
ZStack{
文本(字符串(格式:“%.0f”,百分比))
.font(font.custom(“SFCompactDisplay Bold”,大小:56))
}
}
}
结构大纲:视图{
var步骤:绑定
风险值百分比:CGFloat=20
变量颜色:[Color]=[Color.trackProgressBarColor]
var body:一些观点{
ZStack{
圈()
.填充(颜色.透明)
.框架(宽度:250,高度:250)
.覆盖(
圈()
.修剪(从:0到:百分比*0.01)
.stroke(样式:StrokeStyle(线宽:20,线帽:。圆形,线连接:。圆形))
.fill(角度梯度(梯度:.init(颜色:颜色),中心:.center,星形缠结:.zero,端角:.init(度:360)))
).animation(.spring(响应:2.0,阻尼分数:1.0,混合持续时间:1.0))
}
}
}

在stepview中调用CIRCULARPROGRESS时,我在stepview中遇到此错误。我想我试图以错误的方式获取数据。

我不认为有必要在这里绑定,所以只需将相应的位置替换为简单的
Int

struct CircularProgress: View {
  var steps: Int

struct Outline: View {
    var steps: Int