开发者

Coredata integration into existing application problem iphone

开发者 https://www.devze.com 2023-01-06 12:05 出处:网络
I\'m integrating coredata into my existing application as given in http://wiresareobsolete.com/wordpress/2009/12/adding-core-data-existing-iphone-projects/.

I'm integrating coredata into my existing application as given in http://wiresareobsolete.com/wordpress/2009/12/adding-core-data-existing-iphone-projects/.

I'm facing a problem in insertion of data. My data isn't getting inserted into the following entity.

I'm importing coredata framework into the class Editorial.

@interface Editorial : NSManagedObject {
    NSInteger id;
    NSString *type;
}

@property (nonatomic, assign) NSInteger id;

@property (nonatomic, retain) NSString *type;

And in Editorial.m I'm writing:

@implementation Editorial

@synthesize id, type;

In my .xcmodel also, Editorial is subclassing NSManagedObject and having the mentioned variables with corresponding types.

I think I'm missing something very obvious. But I'm not getting it. Generally while using coredata, if created at the beginning of the project, it automatically inserts attributes an开发者_开发百科d they are not declared in interface and are synthesized with @dynamic. But while integrating coredata at later time, should the corresponding classes be created the way coredata creates them for us?

EDIT: This is how I'm inserting values for Editorial object.

   self.managedObjectContext = appDelegate.managedObjectContext;

    newEditorial = (Editorial *)[NSEntityDescription 
                                             insertNewObjectForEntityForName:@"Editorial" 
                                             inManagedObjectContext:self.managedObjectContext];

    strTitle = [NSString stringWithFormat:@"%@",[object valueForKey:@"eletitle"]];
    [newEditorial setEletitle:[NSString stringWithFormat:@"%@", strTitle]];
    [newEditorial setElecompany:[NSString stringWithFormat:@"%@", strTitle]];   // CRASHING HERE

    [self saveAction];

One more thing that it's crashing at the 2nd string insertion at shown line. I'm getting

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSManagedObject setElecompany:]: unrecognized selector sent to instance 0x4658800' at this line.

NSString *eleCompany exists in the specified coredata entity as well as the class. Also strTitle is containing string and not assigning it to eleTitle as well as eleCompany both of which are strings and exist in class as well as in coredata entity.

Can anybody please help?

This' really urgent.

Thanx in advance.


  1. NSManagedObject instances probably do not contain NSInteger attributes — you probably meant to use NSNumber instead, which is a Core Foundation object type that can be serialized in Core Data.

  2. id is a keyword and very likely reserved. Try naming your NSNumber attribute differently.

  3. After updating your model with new attribute and relationship changes, you will always need to modify or recreate header and implementation files for your managed objects.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号