I have two simple modules in my Swift program. One maintains a list of Locations and the second maintains a list of Activities. The locations module works fine while the Activities module freezes! I can’t select any of the listed activities, etc. The code for these two modules is “identical” what am I doing wrong?
The location module contains the following body:
var body: some View {
NavigationStack {
if locations.isEmpty {
ContentUnavailableView("Enter the first location", systemImage: "location")
} else {
List {
ForEach(locations) {location in
NavigationLink {
EditLocationView(location: location)
} label: {
Text(location.name)
}
}
.onDelete { indexSet in
indexSet.forEach { index in
let location = locations[index]
context.delete(location)
}
}
}
}
}
.navigationTitle("Locations:")
}
and the activities body is:
var body: some View {
NavigationStack {
if activities.isEmpty {
ContentUnavailableView("Enter the first activity", systemImage: "figure.hiking")
} else {
List {
ForEach(activities) {activity in
NavigationLink {
EditActivityView(activity: activity)
} label: {
Text(activity.name)
}
}
.onDelete { indexSet in
indexSet.forEach { index in
let activity = activities[index]
context.delete(activity)
}
}
}
}
}
.navigationTitle("Activities:")
}