I'm having a beginner types problem in swift and the error message isn't very helpful. I get the error
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
from the following code:
import Foundation
import SwiftUI
import CoreGraphics
struct SwiftUIView: View {
let alphabet = ["a","b","c","d","e"]
var body: some View {
GeometryReader { geometry in
let clockPadding = CGFloat(20)
let width = min(geometry.size.width, geometry.size.height)
let diam = width - 2*clockPadding
let centre = width/2
let radius = diam/2
let theta: CGFloat = 2*CGFloat.pi/CGFloat(alphabet.count)
ForEach(0..<alphabet.count) { i in
let x = centre + radius * cos(i*theta)
let y = centre + radius * sin(i*theta)
Text(alphabet[i])
.position(x: x, y: y)
}
}
}
}
In fact the error is still there even when I make the trig functions take a constant, changing the ForEach to:
ForEach(0..<alphabet.count) { i in
let x = centre + radius * cos(0*theta)
let y = centre + radius * sin(0*theta)
Text(alphabet[0])
.position(x: x, y: y)
}
What I'm trying to do is arrange the letter evenly around a circle.