Skip to content
Khoa Pham@onmyway133

How to force refresh in ForEach in SwiftUI for macOS

1 min readUpdated Nov 20, 2020

For some strange reasons, content inside ForEach does not update with changes in Core Data NSManagedObject. The workaround is to introduce salt, like UUID just to make state change

struct NoteRow: View {
    let note: Note
    let id: UUID
}

List {
    ForEach(notes) { note in
        NoteRow(note: note, id: UUID())
    }
}

Keep reading

Type to search titles and full text.

↑ ↓ move↵ openPagefind