I am currently looking through documentation and the web, but I am not seeing what I am looking for and I would just like to confirm if what I am looking for exists:-)
As I understand it - this line of code allows me to add a record to the SQLite database which I am showing in my app through Core Data:
NSManagedObject *newSoftware = [NSEntityDescription insertNewObjectForEntityForName:
Now is there a line similar to that that allows me to update the record I am working on?
something like this?
NSManagedObject *newSoftware = [NSEntityDescription updateCurrentObjectForEntityForName:
Thank you very much for the feedback:-)
To update a specific object you need to set up a NSFetchRequest . This class is equivalent to a SELECT statetement in SQL language. The array results contains all the managed objects contained within the sqlite file. If you want to grab a specific object (or more objects) you need to use a predicate with that request.
Core Data is a framework that you use to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence.
Use Core Data to save your application's permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device. To sync data across multiple devices in a single iCloud account, Core Data automatically mirrors your schema to a CloudKit container.
If your project requires encryption or speed, then Realm is an obvious choice. If your project has a complex data model that changes frequently, then Core Data might be a better choice.
To update a record, you simply update the NSManagedObject
's properties. If you're using CoreData, you should have NSManagedObject
s for each of your "tables". Get a reference to an object after you've queried the database (using NSFetchRequest
). Then you can update the record like this: myObject.firstName = "John";
When you're ready to update the object in your Sqlite database, just call your NSManagedContext
's save
method. I suggest play with a CoreData sample app (like the default one generated by Xcode) to understand this better.
Here my previous answer on it. It is quite detailed to understand what is going on.
How to update existing object in Core Data?
Based on fumoboy007 comment, you have to update your object trough KVC if you have not set up a subclass for your managed object. If you haven't already I suggest to create it. The code looks like more cleaner since you can acess a managed object through properties.
Here a link on it:
organising-core-data-for-ios
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With