Search code examples
iphoneobjective-ccore-data

Convert NSObject to NSManagedObject


I am about to change a part of my application over to CoreData. I have a custom class that I wrote that I want to convert to NSManagedObject. Before I go through all of this I would like to make sure that it will work. Do I just need to make an entity in the CoreData file and change the subclass? are there any other considerations?


Solution

  • The documentation is very useful on this point. In particular, you want to read the part of that document named 'Subclassing Notes'.

    Things to consider would include: are you using any objects that are not supported by Core Data? If so, you'll want to either make them non-persistant, or if that isn't an option you'll want to look at implementing non-standard persistent attributes

    The documentation I've linked to above should be pretty helpful: it's pretty clear and straightforward. To be honest it is difficult to tell how much of an effort it will be on your part: if your NSObject subclass is relatively simple it could be a very straightforward process. But if you're working with something more complex you will want to consider the points raised in the docs above.