I have an iOS application that uses core data.
I’ve built my NSManagedObjectModel. I have an NEOrder entity there.
I’ve generated NSManagedObject subclasses.
@interface NEOrder : NSManagedObject
@property //....
@end
I have a UIViewController’s subclass. That needs to have and instance variable of type NEOrder.
But I want it to behave like a common custom object:
@interface NEOrder : NSObject
@property //....
@end
Of course it can be done by creating another .h and .m file with declaration of NEOrder_ subclassing NSObject there. But this file will be very similar to core data generated NSObjectModels, except @synthesize/@dynamic and init method.
I don’t want to do the work twice.
Help me please, how can it be done?
if I’m adding init to the generated NEOrder app gets crashed:
-(id)init
{
if (self=[super init])
{
self.name=[[NSString alloc] init];
self.phone=[[NSString alloc] init];
self.weight=[[NSNumber alloc] init];
self.fromDirection=[[NEDirection alloc] init];
self.toDirection=[[NEDirection alloc] init];
}
return self;
}
And another few words about how I want to use it.
//NEOrder *order is an instance of view controller
self.order=[NEOrder alloc] init]
//...
self.order.name=@"order name";
self.order.phone=@"12344321";
Is it possible? Or I have to create a separate NSObject’s subclass for that?
One part of your question doesn’t make sense:
What do you mean?
The rest of your question suggests you need a single
NEOrderclass, and that you should set up your view controller like this:MyViewController.h:
MyViewController.m: