ForEach with calculations between each cell

I'm attempting to add a TimeInterval calculated at each step of a ForEach to a Date (hr & min) of the previous cell.

For each cell this works: Start Time = 12:55 Delta interval = 3600 seconds (1hr) Next time = 1:55

I want to use that Next time as the start one for the next cell - instead what I have working is

Delta interval = 30 (5 min) Next time = 1:00 but what I want is 2:00 (12:55 + 1hr + 5min)

I'm just having trouble thinking through how to do that.

Thanks!

Hmm, this sounds like something at a data level, which may not be the responsibility of the ForEach.

What does your model look like? Traditionally, you could do this with a .reduce on a standard Swift collection, and pass the result into SwiftUI's ForEach.

Though I'm not quite sure I understand your question fully. Could you elaborate or show a code example?

Thanks :)

In CoreData I have a TaskEntity with taskHours, taskMins & taskDelta all as Int32's.

I calculate the taskDelta from user inputs to each taskHour and taskMin for each task.

Starting from an initial Date(time) I add the task.taskDelta within the ForEach. Which works great!

I need a way to work with the previous value. I tried using indices but I couldn't get that working.

 @FetchRequest<TaskEntity>(sortDescriptors: [])
    private var tasks
.
.
.
    ForEach(tasks, id: \.id) { task in
.
.
.
Text("\(progTimeInitial +  TimeInterval(task.taskDelta), formatter: Self.TFormatter)")




ForEach with calculations between each cell
 
 
Q