title: Swift Core-Data delete items from attribute list
body: <p>I am working on a core data project.
  Currently I have one Entity (Item) with the following attributes:</p>
  <pre><code>@NSManaged public var title: String?
  @NSManaged public var list: [String]
  </code></pre>
  <p>I am displaying the Entitys in a list using a List with ForEach. With a navigation link I open up another view if the user selects one Item.</p>
  <p>Main List Code:</p>
  <pre><code>struct ItemList: View {
  @Environment(\.managedObjectContext) var viewContext
  @FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Item.title, ascending: true)]) 
  var ItemFetch: FetchedResults&lt;Item&gt;
  
     var body: some View {
        NavigationView {
           List {
              ForEach(ItemFetch, id: \.self {item in
                 NavigationLink(destination: ItemView(Item: item) {
                    Text(item.title)
                 }
              }
              .onDelete(perform: removeItem(at:))
           }
        }
     }
     private func removeItem(at offsets: IndexSet) {
             for index in offsets {
                 let item = ItemFetch[index]
                 viewContext.delete(item)
          }
      }
  }
  </code></pre>
  <p>Second View Code:</p>
  <pre><code>struct ItemView: View {
  
  @Environment(\.managedObjectContext) var viewContext
  @ObservedObject var Item: Item
  
  var body: some View{
  NavigationView {
     List {
        ForEach { Item.list.indices { entry in
           Text(self.Item.list[entry]
        }
     }
     .navigationBarItem(
            trailing:
                 Button(action: {
                     self.Item.list.append(&quot;SubItem&quot;)
         }) {
                     Text(&quot;Add SubItem&quot;)
          })
        }
     }
  }
  </code></pre>
  <p>The user can add a SubItem to the list by pressing a button.</p>
  <p>Also can the Items in the Item List be removed by swiping.</p>
  <p>Now I want that the user can remove SubItems in the SubItems List by swiping as well.
  If I try to implement the same func then the user will remove a Item by deleting a SubItem which is not what I want.</p>
  <p>I don't know how to use the FetchRequest to only fetch the attribute called list. Is there a way to do this or another way to delete the SubItems?</p>
  <p>Thanks.</p>