1

I build a todo app by using @SectionedFetchRequest to fetch the CoreData in IOS 15, I have two entity, one is "group" , the other is "Item", the relationship such as below:

relationship

the code is here:

// fetch request

       @SectionedFetchRequest(
        sectionIdentifier: \TodoListGroup.group,
        sortDescriptors: [SortDescriptor(\TodoListGroup.date, order: .forward)],
        animation: .default
    ) private var todos: SectionedFetchResults<String, TodoListGroup>

// view

   ForEach(todos) { section in
      Section(header:
      HStack {
          Text(section.id)
          Spacer()
      }) {
          ForEach(section) { group in
                                        
             ForEach(group.itemsArray) { item in
                 Text(item.content)
             }
          }
     }
    }
}

I can add, delete group or items ,it's no problem and the console debug show:

▿ Section
  ▿ results : 1 element
    - 0 : <TodoListGroup: 0x600001ca9220> (entity: TodoListGroup; id: 0x944fd1b9b585c7fc <x-coredata://670F71DD-39DA-47BD-987D-7075311C04A1/TodoListGroup/p6>; data: {
    date = "2021-11-05 03:20:59 +0000";
    group = SwiftUI;
    items =     (
        "0x944fd1b9b405c7ec <x-coredata://670F71DD-39DA-47BD-987D-7075311C04A1/ToDoListItem/p10>",
        "0x944fd1b9b425c7ec <x-coredata://670F71DD-39DA-47BD-987D-7075311C04A1/ToDoListItem/p11>"
    );
})
  - id : "SwiftUI"

but when i reopen my app in Xcode, the section.id changed ,like this:

▿ Section
  ▿ results : 1 element
    - 0 : <TodoListGroup: 0x600001a2e6c0> (entity: TodoListGroup; id: 0xb1980459e3a37372 <x-coredata://670F71DD-39DA-47BD-987D-7075311C04A1/TodoListGroup/p6>; data: {
    date = "2021-11-05 03:20:59 +0000";
    group = SwiftUI;
    items = "<relationship fault: 0x6000039185a0 'items'>";
})
  - id : "Drawing"

the id changed to another group's name, why ?

m4n0
  • 29,823
  • 27
  • 76
  • 89
Chr1s78
  • 33
  • 1
  • 5
  • 1
    Welcome to Stack Overflow! Please take the [tour](https://stackoverflow.com/tour) and see: [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). There is a great deal of code you are not showing that could affect this. We will need a minimal, reproducible example... – Yrb Nov 05 '21 at 12:02

0 Answers0