Reputation: 73
I have a custom NSManagedObject Class That Looks Like This.
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class Ingredient, MenuCategory, Price, ItemSize;
@interface Item : NSManagedObject
@property (nonatomic, retain) NSNumber * collected;
@property (nonatomic, retain) NSString * desc;
@property (nonatomic, retain) NSString * instructions;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * quantity;
@property (nonatomic, retain) NSNumber * selected;
@property (nonatomic, retain) MenuCategory *menuCategory;
@property (nonatomic, retain) NSSet *prices;
@property (nonatomic, retain) NSSet *itemSizes;
@property (nonatomic, retain) NSSet *itemIngredients;
-(NSMutableSet *)mutablePrices;
-(NSMutableSet *)mutableItemIngredients;
@end
#import "Item.h"
#import "Ingredient.h"
#import "MenuCategory.h"
#import "Price.h"
#import "ItemSize.h"
@implementation Item
@dynamic collected;
@dynamic desc;
@dynamic instructions;
@dynamic name;
@dynamic quantity;
@dynamic selected;
@dynamic itemIngredients;
@dynamic menuCategory;
@dynamic prices;
@dynamic itemSizes;
-(NSMutableSet *)mutablePrices{
return [self mutableSetValueForKey:@"prices"];
}
-(NSMutableSet *)mutableItemIngredients{
return [self mutableSetValueForKey:@"itemIngredients"];
}
@end
Nothing so special RIGHT ??? The Following Should Work Right ????
[item.mutablePrices addObject:newPrice]
BUT IT DOES NOT GIVES ME THE FOLLOWING ERROR
2014-03-30 10:25:34.594 restos[1192:60b] -[NSManagedObject mutablePrices]: unrecognized selector sent to instance 0xe8d72c0
2014-03-30 10:25:34.597 restos[1192:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject mutablePrices]: unrecognized selector sent to instance 0xe8d72c0'
BUT WHEN I DO THE FOLLOWING
[[item mutableSetValueForKey:@"prices"] addObject:newPrice];
WORKS JUST FINE --- I KNOW IS SOMETHING SIMPLE FOR SOME REASON I CAN NOT SEE IT ----
THANK YOU IN ADVANCE
Upvotes: 1
Views: 1120
Reputation: 539685
The error message
-[NSManagedObject mutablePrices]: unrecognized selector sent to instance 0xe8d72c0
indicates that your item
object is not an instance of the Item
class. A possible reason could be that you did not set the class of the entity to "Item" in the Core Data
model inspector.
Generally it is less error prone if you let Xcode generate the NSManagedObject subclass files (from the Edit menu), and add your custom methods in a Class Category. Alternatively, use "mogenerator".
Upvotes: 2