Good morning all,
I am working on one of my programs that I had setup under the old NavigationView and was using a navigation style of stack
. I am trying to make it work with the new NavigationSplitView
so I can better utilize the screen realestate. I am getting this error and not sure why?
error build: Initializer 'init(_:rowContent:)' requires that '[Program]' conform to 'Identifiable'
I am having some trouble and I a don't know why? Under the current stack when I display the programs its sectioning them out under Scheduled
& Completed
. Heres the code that I use:
Sectioning
what comes back from this function is an [[Program]]
func sectionedPrograms(_ searchString: String, howManyToShow: Int) -> [[Program]] {
// Reduce by filtering on searchTerm
let filteredList = programs.filter { searchString.appearsIn($0.name) || searchString.appearsIn($0.date.dateText(style: .medium)) }
// Separate out by statusText
let dictionaryByStatus = Dictionary(grouping: filteredList, by: { $0.statusText })
// Return the array of dictionary entries. There will be two. If both are nil, the result
// is an empty list - and it should be.
if let completedPrograms = dictionaryByStatus[Status.completed] {
// If we are here then we are returning only the first howManyCompletedProgramsToShow
let programs = Array(completedPrograms.prefix(howManyToShow))
return [dictionaryByStatus[Status.scheduled], programs].compactMap { $0 }
}
return [dictionaryByStatus[Status.scheduled]].compactMap { $0 }
}
View Code
NavigationSplitView {
GeometryReader { geo in
ZStack {
VStack {
if dataManager.programs.isEmpty {
// This displays a message to user informing them that
// there are no programs created.
NoProgramsView()
} else {
// This displays a list of all programs from CoreData
List(dataManager.sectionedPrograms(searchTerm, howManyToShow: howManyCompletedProgramsToShow)) { section in
Section(header: SectionHeaderView(headerName: section[0].statusText)) {
List(section, selection: $selectedProgram) { program in
ProgramsRowView(program: program)
}
}
}
}
} // End of VStack
// Places a floating action button in the bottom right of the view
VStack {
Spacer()
CreateNewProgramActionButton(action: { showAddNewProgram.toggle() }, proxy: geo)
} // End of VStack
} // End of ZStack
.navigationTitle(.nbProgramsViewTitle)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
returnNavBarItems()
}
}
.fullScreenCover(isPresented: $showAddNewProgram, onDismiss: {
dataManager.save()
}) {
NavigationStack {
AddNewProgramView(dataManager: dataManager)
.environmentObject(dataManager)
.interactiveDismissDisabled()
}
}
} // End of GEO Reader
} detail: {
if let program = selectedProgram {
ModifyExistingProgramView(program: program, dataManager: dataManager)
}
}
I would appreciate any help or suggestions anyone has.
Thanks Taz