代码有问题吗?使用这个谓词我什么也得不到。注释掉谓词,然后我可以从实体“BankDetail”中获取所有对象。所以我认为问题在于这两行。
// self.bankInfo.name is set in prepareForSegue in first view controller
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"info.name = %@",self.bankInfo.name];
[request setPredicate:predicate];
我的模型包括两个实体,它们是一对一的关系
银行信息.h
@class BankDetail;
@interface BankInfo : NSManagedObject
@property (nonatomic, retain) NSString * city;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * state;
@property (nonatomic, retain) BankDetail * detail;
@end
银行明细.h
@class BankInfo;
@interface BankDetail : NSManagedObject
@property (nonatomic, retain) NSString * closeDate;
@property (nonatomic, retain) NSString * updateDate;
@property (nonatomic, retain) NSString * zip;
@property (nonatomic, retain) NSString * acquiringInstitution;
@property (nonatomic, retain) BankInfo * info;
@end
编辑:
要提供更多详细信息:
self.bankInfo.name
绝对设置,我 NSLog 它就在谓词行之前我这样做
viewDidLoad
:NSEntityDescription *entity = [NSEntityDescription entityForName:@"BankDetail" inManagedObjectContext:context]; NSLog(@"[entity description] is %@",[entity description]);
在控制台中获取:
info = "(<NSRelationshipDescription: 0x6d3eb30>), name info, isOptional 1, isTransient 0, entity BankDetail, renamingIdentifier info, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, destination entity BankInfo, inverseRelationship detail, minCount 1, maxCount 1, isOrdered 0, deleteRule 2";
EDIT2: 结果predicate 没有任何问题。该错误是由其他地方的粗心错误引起的(请参阅已接受的答案,它与重命名有关)。如果您对谓词有疑问,请忽略此帖子。