1
我有一個自定義NSManagedObject類看起來像這樣。NSManagedObject自定義類 - NSInvalidArgumentException無法識別的選擇器 -
#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
沒有那麼特別RIGHT ??? 以下應該工作正確?
[item.mutablePrices addObject:newPrice]
,但它不給我下面的錯誤
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'
,但是當我這樣做
[[item mutableSetValueForKey:@"prices"] addObject:newPrice];
工作得很好---我所知道的是一些簡單的出於某種原因我看不到它----
先謝謝你