# Edit a list item (using CoreData)

**URL:** <https://forums.swift.org/t/edit-a-list-item-using-coredata/54276>\
**Category:** Using Swift\
**Tags:** off-topic, swiftui, core-data\
**Created:** [December 25, 2021, 11:47pm UTC](https://forums.swift.org/t/edit-a-list-item-using-coredata/54276 "2021-12-25T23:47:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Timo](https://avatars.discourse-cdn.com/v4/letter/t/c4cdca/32.png) [@Timo](https://forums.swift.org/u/Timo)\
**Post date:** [December 25, 2021, 11:47pm UTC](https://forums.swift.org/t/edit-a-list-item-using-coredata/54276/1 "2021-12-25T23:47:21Z")

</div>

Hi together,

I'm currently building an app, where I have a `List`, in which each item links to a detail view using `NavigationLink`. The data is stored using CoreData. So far, everything works.

I now would like to modify the data in the DetailView. For simplicity, I first wrote the following code, that uses an store-object. This does work.

**MainView:**

```swift
@ObservedObject var birthdayStore = BirthdayStore()
// ...
List{
    ForEach(filteredBirthdays){ birthday in
        NavigationLink(destination: BirthdayDetail(birthday: self.$birthdayStore.birthdays[self.birthdayStore.birthdays.firstIndex(of: birthday)!])){
            // Display item
        }
    }
}

```

**Detail-View:**

```swift
struct BirthdayDetail: View {
    @Binding var birthday: Birthday
    
    var body: some View {
        Form{
            TextField("Name", text: $birthday.name)
        }
        .navigationTitle(birthday.name)
    }
}

```

I now tried to achieve the same thing using core data, but struggle to get it to work.  
In the Main-View, I now fetch my data like so:

```swift
@Environment(\.managedObjectContext) private var moc
    
@FetchRequest(entity: Birthday.entity(), sortDescriptors: [])
private var birthdays: FetchedResults<Birthday>

```

Would be great, if someone could help me with this! :)

---

<div class="post-metadata">

**Author:** ![plsalvado](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/plsalvado/32/25142_2.png) [@plsalvado](https://forums.swift.org/u/plsalvado)\
**Post date:** [September 8, 2022, 5:20pm UTC](https://forums.swift.org/t/edit-a-list-item-using-coredata/54276/2 "2022-09-08T17:20:54Z")

</div>

I'm curious as to whether you found a solution for this.
