1
我有一個像實體中的以下內容:是否可以在NSFetchRequest的NSPredicate中使用父實體的屬性?
@interface A : NSManagedObject
{
}
@property (nonatomic, retain) NSString *stringProperty;
具有子實體b類似這樣:
@interface B : A
{
}
我想利用存儲在A.事物的性質上B中取像這樣:
NSManagedObjectContext *context = [delegate mainManagedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"B" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"stringProperty = %@", someString];
[request setPredicate:pred];
這可能嗎?我目前收到以下錯誤:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath stringProperty not found in entity <NSSQLEntity B id=26>'
你能描述你的實體層次多一點,並顯示你正在使用的實際謂詞嗎? – 2011-02-23 20:04:07
我已更新我的問題,更具體的代碼片段。 – cmour 2011-02-24 22:40:38