Help with two errors on .trim(from: 0, to: 1 - CGFloat(self.sliceSize)) * CGFloat(self.progress)) line

import SwiftUI

import PlaygroundSupport


struct ProgressView: View {

    let gradientColors: [Color] = [Color( colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)), Color( colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0))]

    let sliceSize = 0.35

    let progress: Double

    

    private let percentageFormatter: NumberFormatter = {

        let formatter = NumberFormatter()

        formatter.numberStyle = .percent

        return formatter

    } ()

    

    init(_ progress: Double = 0.3) {

        self.progress = progress

    }

    

    var body: some View {

        GeometryReader { geometry in

            ZStack {

                Group {

                    Circle()

                        .trim(from: 0, to: 1 - CGFloat(self.sliceSize))

                        .stroke(self.strokeGradient, style: self.strokeStyle(with: geometry))

                        .opacity(0.5)

                    Circle()

                      .trim(from: 0, to: 1 - CGFloat(self.sliceSize)) * CGFloat(self.progress))

                    .stroke(self.strokeGradient, style: self.strokeStyle(with: geometry))

                    

                        

                } .rotationEffect(.degrees(90) + .degrees(360 * self.sliceSize / 2))

            }

        }

    }

}

Yes... what are the errors? Where do they appear?

When I test, I get many more errors, such as "ProgressView has no strokeStyle property".

Help with two errors

It’s hard to offer help with just a code snippet. Please post more details. See tip 7 in Quinn’s Top Ten DevForums Tips.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I get other errors when trying your code, such as

  • Cannot find 'colorLiteral' in scope (needed #colorLiteral

  • The key error is that you have an extra closing parenthesis:

                      .trim(from: 0, to: 1 - CGFloat(self.sliceSize)) * CGFloat(self.progress))

should be

                      .trim(from: 0, to: 1 - CGFloat(self.sliceSize) * CGFloat(self.progress))
  • You declare gradientColors but use strokeGradient.
  • ProgressView has no member 'strokeStyle'. So you probably missed to show how you defined the func strokeStyle(with:)
Help with two errors on .trim(from: 0, to: 1 - CGFloat(self.sliceSize)) * CGFloat(self.progress)) line
 
 
Q