I am creating a workout app using CoreData, where it gives you a workout to do. Within each workout you are given 4 sets to do, the sets are buttons, and you are able to track how many sets/reps you did. Once you enter how many sets/reps you did, the button will change from “Set: 1” how set it supposed to look like to “# of reps x # of weight”. I was able to figure out this code and able to save it to CoreData, this issue i’m having is allowing each button to have their own set. When ever I update one set/button, it syncs across all buttons. I would like each button to have their own set/connection to coreData, but im not sure how to do that. I have attached pictures to show the before and after between when coreData is empty vs when it’s not. Set with all buttons sync across (dont want that)
I made sure that within coreData my entity is set to “to-Many”. I have created an if-else statement:
@FetchRequest(sortDescriptors: []) var reps: FetchedResults
if reps.isEmpty {
SetTrackerButton()
} else {
EditedTrackButton()
}
I know that the issue is the else statement. the moment that “reps” entity is not empty, it’s going to display across all the buttons. I have tried a forEach loop within the if-else statement and it did not work:
ForEach(1..<5, id: .self) { _ in
if reps.isEmpty {
SetTrackerButton()
} else {
EditedTrackButton()
Im a little stuck, and not how I can fix it. Any ideas?
thanks
user23665023 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.