Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type ‘()’ cannot conform to ‘AccessibilityRotorContent’

Tags:

swiftui

Driving me nuts… I have a class called TrackPiece2 with a bunch of var’s in it… I have an array of these and I want to change a value in each TrackPiece2 of the array… but I am getting the error “Type ‘()’ cannot conform to ‘AccessibilityRotorContent’” on the ForEach line of func changeZoom below


class TrackPiece2: Identifiable {
    var id: UUID = UUID()
    var centerPnt: CGPoint = CGPoint.zero
    var radius: CGFloat = 0.0
    var width: CGFloat = 0.0
    var startAngle: Angle = Angle.zero
    var angleArc: Angle = Angle.zero
    var color: Color = Color.clear
    var zoom: CGFloat = 1.0
.
.
.
class TrackLayout2 {
    var trackPieces: [TrackPiece2] = []
    var drawOuterLines: Bool = false
    
    func addTrackPiece(newTrkPc: TrackPiece2) {
        self.trackPieces.append(newTrkPc)
    }
    
    func changeZoom(newZoom: CGFloat) {
        ForEach(trackPieces) {    <——— Error occurs here
            trkPc in
            trkPc.zoom = newZoom
        }
    }
    
    func loadTrackPieces() {
        let centerPoint = CGPoint(x: 160, y:160)
        
        addTrackPiece(newTrkPc: TrackPiece2(centerPnt: centerPoint, radius: 160.0, width: 10.0, startAngle: Angle(degrees: 0), angleArc: Angle(degrees: 45), color: Color.pink, zoom: 0.5))
    }
}

Interesting… but if I replace the entire ForEach {} in func changeZoom with a specific member of the array, ‘trackPieces[0].zoom = newZoom’, it works fine…

Also, TrackPiece2 is Identifiable… I also made it Hashable as well… but that didn’t change anything so I left it as Identifiable only

Thanks for any advice/help… TJ

like image 868
tj4shee Avatar asked Oct 19 '25 12:10

tj4shee


1 Answers

Ugh ! Thanks vadian… changing

ForEach(trackPieces) {
            trkPc in

to

for trkPc in trackPieces {

fixed the problem.

like image 161
tj4shee Avatar answered Oct 21 '25 22:10

tj4shee