I have a book list on which I manage to act on the sorting according to the section but as soon as I have to access a subcategory of an object like "author" to sort via the name and that this one in contains several (example for a comic: a scriptwriter and a cartoonist), I can't do it. (idem for section kinds)
Can you tell me how to proceed?
Thank you so much
List {
ForEach(viewModel.filter, id: \.self) { section in
// create a section in terms of filter
Section {
// Books sorted by section title
ForEach(viewModel.arrayBooks, id: \.id) { book in
if book.title == section { <---- it's example
to section title
NavigationLink {
BookDetailView(book: book)
} label: {
BookVolumeRow(book: book)
}
}
}
//onDelete only works with ForEach
.onDelete(perform: { indexSet in
viewModel.deleteRow(indexSet: indexSet)
})
}
var example: [Book] = [
Book(kinds: [.action, .comedy, .adventure], <----- problem here,
I want the book appear
thrice (once by kind)
title: "My book",
volume: 8,
imageName: "Image_Book",
authors: [Author(name: "John Doe"), <----- problem here
Author(name: "Jeanne Doe")] I want the book appear
twice (once by author)
publisher: "BookFab",
synopsis: "Text description",
]
enum SortFilter: String, CaseIterable, Identifiable {
//create id for Identifiable
var id: Self {
return self
}
case title
case author
case publisher
case kind
case category
}
I try to use a loop "forEach" for the authors and kinds but i retrieve only the last item