0

User can delete some Core Data in NavigationLink. How to save it when back button clicked and return to NavigationView?

1 Answer 1

1

You can do it in the onAppear method of the previous View in the NavigationalStack.

struct ContentView: View {
    @Environment(\.managedObjectContext) var managedObjectContext
    var body: some View {
        Text("")
            .onAppear {
                do {
                    try self.managedObjectContext.save()
                } catch {
                    // handle the Core Data error
                }
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.