Updating core data externally

I have just bought my first course from RayWenderlich.com and I am learning a great deal about Core Data. At this time, I am puzzled by one thing - I am starting to see how XCode implements persistence with Core Data. Is there a way to have the persistent store read from an external source? For example, could a banking app, where data changes all the time use Core Data? Also, do you need to post a new app on the app store every time your data changes?

Updating core data steps-
In the app, we use the didSelectRowAt method to detect when you tap on a note from the list, and we pass the data to the AddNoteViewController to edit them. When the edit is done, we return the data using a closure (the same as we do with new notes)

Go to didSelectRowAt, and replace the saveNote closure with the following code to update the data in Core Data.

addNoteVC.saveNote = { [weak self] noteText, priorityColor in
guard let self = self else { return }
self.notes[indexPath.row].setValue(noteText, forKey: #keyPath(Note.noteText))
self.notes[indexPath.row].setValue(priorityColor, forKey: #keyPath(Note.priorityColor))
DispatchQueue.main.async {
self.tableView.reloadRows(at: [indexPath], with: .fade)
Code language: Swift (swift)
And also, above the closure pass optional arguments in the setNote

addNoteVC.setNote(text: currentNote.noteText ?? “”, priorityColor: currentNote.priorityColor ?? UIColor.clear)

// …

addNoteVC.saveNote = { [weak self] noteText, priorityColor in
// …

This may help you,
Rachel Gomez

This topic was automatically closed after 166 days. New replies are no longer allowed.