I have the same issue, if I sort the onDelete feature doesn’t work. Without sort it works. Here is the code.
struct tempView: View {
@ObservedRealmObject var user: User
private let sortDescriptors = [
SortDescriptor(keyPath: "name", ascending: true)
]
var body: some View {
VStack {
// Works with no sorting
// if let activities = user.activties {
// Delete doesn't work with sorting
if let activities = user.activties.sorted(by: sortDescriptors) {
List {
ForEach(activities) { activity in
ActivityRow(activity: activity.name)
}
.onDelete(perform: $user.activties.remove)
}
}
}
}
}
It seems pretty clear to me now that Realm’s SwiftUI support is experimental / prototype-level, and that many standard expectations of iOS interfaces (such as list sorting, optional selection objects, scene state restoration) require nasty workarounds if able to find one