Core data updating records
So how can you update or delete an existing managed object from database? To allow user to delete a record from the table view, as you know, we can simply implement the “can Edit Row At Index Path” and “commit Editing Style” methods.
Add the following code to the Device View Controller.m: - (BOOL)table View:(UITable View *)table View can Edit Row At Index Path:(NSIndex Path *)index Path - (void)table View:(UITable View *)table View commit Editing Style:(UITable View Cell Editing Style)editing Style for Row At Index Path:(NSIndex Path *)index Path We’ll not go into the details about how to remove a row from table view as we’ve already covered in our earlier tutorial.
Even without learning SQL and database, you’re able to perform create, select, update and delete operation.
However, for those with database background, you may want to know the exact SQLs executed behind the scene.
However, we only showed you how to insert records into data store through Core Data API and left out the update & delete operations.
Note: If this is the first time you learn about Core Data, we recommend you to read the first tutorial.
It still is, but slightly differently in i OS 10 and beyond. Once that context is returned, We can move on creating Model.
Step 3: Create a Model No class or structure to create for core data objects. In demo, I have used strings in the example below but you can have other data types.
As I already commented, the code is very simple and you need to do some check before. Your app should look similar to the following: Next, we’ll enhance the app to let user update the device information.Go to the Storyboard and add a new segue for the table cell.This is the second article for our Core Data series.Previously, we gave you a brief introduction of Core Data and created a simple app to store all your device information.