Deleting from RealmSwift.List<Object> raises out of bounds exception

I have been trying to follow the ListSwiftUI example provided in the realm-cocoa repo. It has been working very well for me but I have run into a problem, when I try to delete from a RealmSwift.List<Object> the app crashes with an exception "Terminating app due to uncaught exception 'RLMException', reason: 'Index 5 is out of bounds (must be less than 5).'"


final class Todo: Object, ObjectKeyIdentifiable {
    @objc dynamic var id: String = UUID().uuidString
    @objc dynamic var name: String = ""
    @objc dynamic var createdAt: Date = Date()
    override class func primaryKey() -> String? {

final class Todos: Object {
    @objc dynamic var id: Int = 0
    let todos = List<Todo>()
    override class func primaryKey() -> String? {


let realm = try! Realm()
var todos = realm.object(ofType: Todos.self, forPrimaryKey: 0)
if todos == nil {
    todos = try! realm.write { realm.create(Todos.self, value: []) }

// Create the SwiftUI view that provides the window contents.
let contentView = ContentView(todos: todos!.todos)


@ObservedObject var todos: RealmSwift.List<Todo>
var body: some View {
    ForEach(todos) { (todo: Todo) in
        .onDelete(perform: delete)

func delete(at offsets: IndexSet) {
    if let realm = todos.realm {
        try! realm.write {
    } else {
        todos.remove(at: offsets.first!)

I have checked the count of my todos list and the db in Realm Studio, it actually contains the index 5. And this crash is not specific to only index 5, e.g. if I only have 2 items in the list, the app crashes with Index 1 or when it contains 5 items, it crashes with Index 4.

The example has pretty much the same Data Models and it works perfectly. So what am I doing wrong here?