ios - Initializing a subclass of an NSManagedObject's subclass -


I have this subcategory generated from NSManagedObject my core data data model Is:

  @ interface customer: NSManagedObject @property (nonatomic, retain) NSNumber * ID; @protecti (nontomic, write) NSString * firstName; @property (nonatomic, retain) NSString * familyName; @end   

My app's argument defines the subclass of this customer class to give me the expansion of my properties and some methods and to keep them separate The class generated from my data model is led to: @interface ExtCustomer: Customer @ Property (non-nominal, retaining) NSNumber * amendment date; + (Extreme Customer *) Parsezden Data: (NSDT *) JSN data; @end

I do not need to keep this code updated, and whatever I want is to use the entire ExtCustomer objects The customer can save the app instead of the object, but only when needed, via the customer data by core data .

I tried to immediately ExtCustomer calling init , but this is not possible because it received from NSManagedObject happens, so I try to do so:

  + (ExtCustomer *) createExtCustomerInContext: (NSManagedObjectContext *) reference {NSEntityDescription * entityDescription = [NSEntityDescription EntityForName: @ "managed object Contaks customer" : Reference]; ExtCustomer * Customer = [[ExtCustomer alloc] initWithEntity: Insert in Entity EntryMeanaged Contact: Reference]; [Subscriber set FamilyName: @ ""]; [Customer setfirstname: @ ""]; Return customer; }   

But I see, even if I put the object ( returning customer to ExtCustomer *); , which actually gets a < code> customer object because I have my data model ExtCustomer is not defined as a unit, I think I only NSEntityDescription to customer < / Code> can I get. How can I solve it?

Thanks in advance

BTDT and I can not recommend doing it.

When you edit your model and ask to encode to create class files, that code will overwrite any changes (and any code extension) encoded in the class file. I tried to split the model class by definition of model class and by increasing the model model in different ways, but as a result I found many problems in the later stages of the app.

Then recreate your class files to xcode to do not what you want to do basically. After you make changes to the model, you want to manually update your model files. An update in the class file should be required only when the name of an attribute or type changes.

This process requires a little discipline but it is very easy to maintain and administer it in comparison to any class or extension of the model class.

further my model class attribute values ​​(or it's tempting to add logic model class to respond to changes), but when evaluating this approach is the idea that your managed object but Lasts for some time. Do not pass it inside your app The managed object can be changed in error and your logic will no longer be accessible.

Consider moving the logic into a different class, just as NSManagedObject is not received. Copy the necessary attributes for a particular task and display the required logic inside that separate category. That class is not able to make a mistake on you and you will have more freedom with references.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -