开发者

iOS CoreDataGeneratedAccessors and save in one to many

I have used coredata in a project with only a parent and a child [one to many], cd will generate the entity.h and entity.m for NSManagedObject, [ok] the problem is that in my prior project , the addCategToEntityObject in my entityMother.h is

- (void)addCategToEntityObject:(NSManagedObject *)value;

and it works fine,

but in my new project, the CoreDataGeneratedAccessors for the entityMother.h is

- (void)addTo_InterestObject:(Interest *)value;

so I use a kind of same approach to save but now get a warning and in run time crash off course! [but how to fix it!]

WARNING: Incompatible Objective-C types 'struct NSManagedObject *', expected 'struct Interest *' when passing argument 1 of 'addTo_InterestsObject' from distinct Objective-C type

here the action for saving with the problem: -(IBAction) saveInterest: (id) sender{

NSManagedObject *newItem;

NSManagedObjectContext *contextCateg_ = [categ_ managedObjectContext];


NSLog(@"el contexto :%@",contextCateg);

newItem = [NSEntityDescription insert开发者_StackOverflow社区NewObjectForEntityForName:@"Interest" inManagedObjectContext:contextCateg_];


[categ_ addTo_InterestObject:interest_]; //vooddoo! un mensaje del mas alla!



//OJO, COREDATA ME GENERA UN   - (void)addTo_InterestObject:(Interest *)value;
// EN LUGAR De NSManagedObject, 


[newItem setValue:item_new.text forKey:@"interest"];

NSError *error;
[context save:&error];
NSLog(@"ITEM saved");

in the .h

#import <UIKit/UIKit.h>


 @class Categories, Interest;

 @class EventMAppDelegate;
 @class editContactViewController; 


  @interface BackEndViewController : UIViewController <UITableViewDelegate,   UITableViewDataSource, NSFetchedResultsControllerDelegate> {

Categories *categ_; //objetos de los Entities
    Interest *interest_;

NSManagedObjectContext *contextCateg;


The problem is caused because in the first model, your Categ entity had no specified NSManagedObject subclass name defined so the code generator just assigned a generic NSManagedObject value type to the method parameter.

However, in the second model, your Interest entity has NSManagedObject subclass name of Interest defined so the code generator assigned a type of Interest to the method parameter.

As defined, you must pass an object of class Interest to the method. If you don't wish to do this, you must remove the class name from the data model and regenerate the code to accept a generic NSManagedObject.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜