NSManagedObject; save or load into custom NSObject?

I use Core Data to store objects. I have an NSManagedObject Person and a NSObject Person. Both have the same attributes. NSObject has some methods.

I am currently browsing Core Data for Bob. Then I will take this NSManagedObject Bob and copy all the attributes into the NSObject Bob and do what I need.

Does this make sense or should I create the necessary methods in NSManagedObject instead? Is it possible to handle NSManagedObject in the same way as NSObject ?

+4
source share
2 answers

The recommended way is to create a category of your subclass of NSManagedObject and implement your own methods in that category. That way, you can re-create your subclass of NSManagedObject through Xcode if your schema changes and your category stays the same and is not affected.

Link: for example. Paul Hegarty / IOS Standard iOS Courses Basic

+8
source

Yes, you can simply use NSManagedObject as a regular object - it is not only for access to the data warehouse, it is intended for direct use as a model object. Copying data back and forth between instances of different classes like this is a big part of the extra work without any benefit.

Since you are adding custom code, I highly recommend that you use mogenerator to create subclasses of NSManagedObject . This will make it easier to save your custom code if / when you need to change your model.

0
source

Source: https://habr.com/ru/post/1469347/


All Articles