How to make CloudKit compatible when you have enum driven selectable list

For a book club app I’m writing In SwiftUI, I have a NavigationSplitView that has a selectable List on its leading column. The first item on the list is “Book” and will take the user to a book’s PDF if selected. Below it is a Button with a plus icon that allows the user to add a reader of the book. Once a reader is added, their name will appear on a List just below the plus Button. If a user selects a reader, they’ll be taken to their profile page.

The purpose of the whole thing is so that “Book” and the list of readers are integrated into one selectable List, such that when one item is selected, it is highlighted and the previous selected item loses its highlight.

This is the code:

import SwiftUI
import SwiftData

enum ListItem: Hashable
{
    case book
    case reader(Reader)
}

struct ProjectView: View
{
    private let project: Project
    
    @Environment(.modelContext) private var modelContext
    
    @Query private var readers: [Reader]
    
    @State private var alertPresented = false
    @State private var userInput = ""
    @State private var selectedListItem: ListItem?
    
    init(project: Project)
    {
        self.project = project
    }
    
    var body: some View
    {
        NavigationSplitView
        {
            List(selection: self.$selectedListItem)
            {
                Text("Book").tag(ListItem.book)
                
                Divider()
                
                Button(action:
                {
                    self.alertPresented = true
                },
                label:
                {
                    Label("", systemImage: "plus")
                })
                .buttonStyle(PlainButtonStyle())
                
                .alert("Reader Name:", isPresented: self.$alertPresented)
                {
                    TextField("", text: self.$userInput)
                    
                    Button("OK")
                    {
                        let reader = Reader(name: self.userInput)
                        self.modelContext.insert(reader)
                        self.project.readers?.append(reader)
                        self.selectedListItem = ListItem.reader(reader)
                        self.userInput = ""
                    }
                    .keyboardShortcut(.defaultAction)
                    
                    Button("Cancel", role: .cancel) { }
                }
                                    
                ForEach (self.readers , id: .self)
                {
                    reader in Text(reader.name).tag(ListItem.reader(reader))
                }
            }
            .onAppear
            {
                self.selectedListItem = ListItem.book
            }
        }
        detail:
        {
            Text("Detail")
        }
    }
}

It was working fine until I added CloudKit to my project. Now, on occasion, when I add a reader, I get a message:

Fatal error: Duplicate keys of type ‘Reader’ were found in a
Dictionary. This usually means either that the type violates
Hashable’s requirements, or that member of such a dictionary were
mutated after insertion.

Also, this List will not work with CloudKit and update any added readers on other devices (when other screens work fine with CloudKit). When I completely remove enum ListItem and the “Book” item at the top, and simply display a list of readers using self.readers and self.selectedReader in place of self.selectedListItem, then everything works fine. So I believe the issue is with using the enum and combining the “Book” item and the list of readers into one, but I’m not understanding why. Any help would be appreciated! For your reference, below are my Project and Reader model classes:

import Foundation
import SwiftData

@Model
class Project
{
    var name: String = ""
    @Relationship(deleteRule: .cascade, inverse: Reader.projects) var readers : [Reader]?
    
    init(name: String)
    {
        self.name = name
        self.readers = []
    }
}

import Foundation
import SwiftData

@Model
class Reader
{
    var name: String = ""
    
    var projects: [Project]?
    
    init(name: String)
    {
        self.name = name
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật