In addition, do not manipulate an existing Core Data-created SQLite store using the native SQLite API.
If the save method returns a success, the error variable does not need to be consulted.
This is the second article for our Core Data series.
Note: If this is the first time you learn about Core Data, we recommend you to read the first tutorial.
But for those who do not want to start from the very beginning, you can download this Xcode project to continue to work on the below tutorial.
Although Core Data supports SQLite as one of its persistent store types, the database format is private.
You cannot create a SQLite database using the native SQLite API and use it directly with Core Data.
Like saving data, we first grab the manage object context.
[new Vehicle set Value: _txt Field Vehicle for Key:@"number"]; [new Vehicle set Value: lbl Fuel for Key:@"fueltype"]; [new Vehicle set Value: lbl Fuel for Key:@"fuelunit"]; [new Vehicle set Value: lbl Distance for Key:@"distanceunit"]; I want to update my core data entity named "Vehicle", for that entity I have several attributes and I want to update some of them but not all when I select particular attribute from the entity. NSFetch Request *fetch Request=[NSFetch Request fetch Request With Entity Name:@"Vehicle"]; NSPredicate *predicate=[NSPredicate predicate With Format:@"vehicle_id==%@",vehicle_id]; // If required to fetch specific vehicle fetch Request.predicate=predicate; Vehicle *new Vehicle=[[self.managed Object Context execute Fetch Request:fetch Request error:nil] last Object]; [new Vehicle set Value: _txt Field Vehicle for Key:@"number"]; [new Vehicle set Value: lbl Fuel for Key:@"fueltype"]; [new Vehicle set Value: lbl Fuel for Key:@"fuelunit"]; [new Vehicle set Value: lbl Distance for Key:@"distanceunit"]; [self.managed Object Context save:nil] The above line fetches all the objects which exists in your core data store and which satisfies the criteria indicated by fetch Request (if predicate is nil, then it fetches all records belonging to that entity).
In this case, however, the code to create the context (and the rest of the Core Data stack) is explicit.
It is written for you automatically as part of the template.