This is more informative and learning than an actual ticket
My goal is to have a list of performances (custom class), and to have the user select them to then compare two of them.
For this the concept of EditMode is introduced
EditMode is a built in function or thing that when set to .active, it gets the item on a list and enters "edit mode" which if you have a ForEach in the list, and an onDelete method, it will show a selection so user can kindof choose what row they want to delete easily.
If we want something like selecting, instead of the onDelete thing, editMode will look for:
List(selection: $selection)
This parameter tells editmode the intention of the developer as to say, that he wants user to be able to choose from the list (and it gets put in the selection variable)
Here comes in the second BTS swiftUI moment that had me browsing shit for 2 hours:
selection will be a Set of a certain type like:
@State var selection = Set<UUID?>()
Now, here is where one of the things happen. The type is important, because that type is the identifiable property swiftui will use to enable/make work the selection feature. So, in this case I use UUID? because the class that is in the List is a Core Data entity which Identifiable property is:
@NSManaged public var id: UUID?
Bear in mind, the class have to be identifiable, in my case this is done with:
extension UserSavedPerformance : Identifiable { }
So,
This is more informative and learning than an actual ticket
My goal is to have a list of performances (custom class), and to have the user select them to then compare two of them.
For this the concept of EditMode is introduced
EditMode is a built in function or thing that when set to .active, it gets the item on a list and enters "edit mode" which if you have a ForEach in the list, and an onDelete method, it will show a selection so user can kindof choose what row they want to delete easily.
If we want something like selecting, instead of the onDelete thing, editMode will look for:
List(selection: $selection)
This parameter tells editmode the intention of the developer as to say, that he wants user to be able to choose from the list (and it gets put in the selection variable)
Here comes in the second BTS swiftUI moment that had me browsing shit for 2 hours:
selection will be a Set of a certain type like:
@State var selection = Set<UUID?>()
Now, here is where one of the things happen. The type is important, because that type is the identifiable property swiftui will use to enable/make work the selection feature. So, in this case I use UUID? because the class that is in the List is a Core Data entity which Identifiable property is:
@NSManaged public var id: UUID?
Bear in mind, the class have to be identifiable, in my case this is done with:
extension UserSavedPerformance : Identifiable { }