@PaulDP
Hi Paul,
From what I can see the correct date is being saved into CoreData.
In your MeetingsListView the issue is that you are iterating over meeting
(should be named meetings
since it is an array) rather than the dateHolder.selectedMeeting
. Similarly, I would recommend that you refactor and rename selectedMeeting
to selectedMeetings
(more than one meeting may be retrieved)
In DateScroller, as you move forward and backwards you need to refresh the data that populates the selectedMeeting(s)
array so in DateHolder
, remove the fileprivate
keyword preceding the function declaration refreshMeetingItems
then in DateScroller
add a call to the refreshMeetingItems
in each of the moveForward and moveBack() functions. ie:
dateHolder.refreshedMeetingItems(viewContext)
Just a note regarding the way you are injecting an .enviromentObject()
You have injected .environmentObject(dateHolder)
in your Parent View and as such there is no need to inject it anywhere else since you can access it in any view that requires it by using:
@EnvironmentObject var dateHolder: DateHolder
I also noted that the deleteRecord() function needs to be modified so that the correct record in CoreData is removed since the seletedMeeting
array that is being looped over is a subset of meeting
private func deleteRecord(indexSet: IndexSet) {
for index in indexSet {
print(index)
let selectedItem = dateHolder.selectedMeeting[index]
if let itemIndex = meeting.firstIndex(where: { $0.meetingDate == selectedItem.meetingDate}) {
viewContext.delete(meeting[itemIndex])
// And refresh selectedMeeting
dateHolder.refreshedMeetingItems(viewContext)
}
}
Also when you add a new meeting you also need to refresh the selectedMeeting
array if the meeting you are adding is the current day otherwise you don’t see anything. That was doing my head in for a while.
If you want me to post the updated project then let me know otherwise I’ll leave it to you to make the necessary changes in your version. By the way, in the version I have here, I made a number of changes to the naming convention to make it easier for me to understand.
(edit)
I enjoyed the challenge too. 