I am getting Preview Crash. If I remove line 30 below. then the Preview Crash does not occur. I have Restarted XCode, I have done a Project Clean, Then did a project rebuild.
I have also Created a new Project from scratch Named the project Debug, Add one new View File named MaskBootCamp once I select MaskBootCamp The Preview willl Crash with an Circle with a Red X in the center With Preview Crashed.
If I remove line 22 all is resolved and no exception occurs
Is this a Swift Bug or some error in the coding? Excepition Report listed below the code. report Below:
** MaskBootCamp .swift **
import SwiftUI
struct MaskBootCamp: View { @State var rating: Int = 0
var body: some View {
ZStack{
starsView
.overlay(overlayView.mask(starsView))
}
}
private var overlayView: some View {
GeometryReader { geometry in
ZStack(alignment: .leading) {
Rectangle()
.foregroundColor(.yellow)
.frame(width: CGFloat(rating) / 5 * geometry.size.width)
}
//allowsHitTesting(false)
}
}
private var starsView: some View {
HStack{
ForEach(1..<6) {index in
Image(systemName: "star.fill")
.font(.largeTitle)
.foregroundColor(.gray)
.onTapGesture {
rating = index
}
}
}
}
}
#Preview { MaskBootCamp() }