views:

29

answers:

1

Hi all,

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 and 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.

A: 
  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.

Alex Reynolds
For NSInteger value, I'd taken its corresponding type which is Decimal[Please correct me if I'm wrong. According to my information, for NSNumber it's Int32]. Even after changing type to nsnumber and at both the locations the problem still remains. I'm facing the insertion problem specially for string. Also, Please check my edited question. Thanx.
neha
Every time you make a change to the model, you will should remake the corresponding header and implementation files. I recommend you let Xcode do this for you, as it is easy to overlook an attribute or relationship property when manually editing.
Alex Reynolds
What do you mean by "let Xcode do this for you?" Since I'm integrating coredata into my existing app, I need to create the managedObject Classes myself. I think I'm going wrong in creating classes and their connection to coredata otherwise I have integrated coredata in my project properly. This' really eating me now. Is there any good tutorial that guides through steps needed for this issue? Thanx.
neha
You may want to go through the Core Data tutorial: http://developer.apple.com/iphone/library/documentation/DataManagement/Conceptual/iPhoneCoreData01/Introduction/Introduction.html
Alex Reynolds