I currently have a List where it alternates the date (//Climb date group) and then details (//Climb details row) from core data every row.
I only want to show the date row though if it is different from the row above.
List{
ForEach(climbs, id: \.self){ thisClimb in
let gradeText = (thisClimb as? Climb)?.grade
let attemptsText = (thisClimb as? Climb)?.attempts
let passfailText = (thisClimb as? Climb)?.passfail ?? "climb string err"
let newclimbdateText = (thisClimb as? Climb)?.climbdate
//Climb date group
if(oldclimbdateText != newclimbdateText){
HStack{
Spacer()
Text(newclimbdateText!.addingTimeInterval(600), style: .date).fontWeight(.medium)
Spacer()
}
}
//Climb details row
HStack{
Text(gradesV[Int(gradeText!)])
Spacer()
Text("\(attemptsText!) attempts")
Spacer()
Text(passfailText)
}
}.onDelete(perform: deleteClimb)
}
The code above shows this:
So to not show the dates that are the same (see multiple Oct-18 above), what I tried to do is set a variable outside of the loop called @State private var oldclimbdateText and then within the if statement under "//Climb date group" I tried to set `oldclimbdateText = newclimbdateText``. That way on the next loop they do match does not enter the if statement.
However, when I try that I get the error Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols
I'm just doing this for fun to learn. Using Xcode 12 and Swift5.
- Why do I get this error, and 2) is there a better way to get rid of these duplicate date rows?