我有一个有点不重要的包含层次结构,我想尝试使用NSPredicate
查找scopes
列表中的任何元素,其中包含一个名为name
的属性,其值为匹配我提供的。当我构造谓词时,我得到错误:
this class is not key value coding-compliant for the key 'name'
这就是我的班级结构:
@interface FieldData : NSObject
@property (nonatomic, strong) NSArray *scopes;
- (Element *)findElementWithName:(NSString *)name;
@end
@implementation FieldData
- (Element *)findElementWithName:(NSString *)name
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self.name == %@", name];
NSArray *result = [self.scopes filteredArrayUsingPredicate:predicate];
NSLog(@"result: %@", result);
}
@end
Scopes由CustomScope或BasicScope类组成,两者都派生自一个公共类:
@interface Scope : NSObject
@end
@interface BasicScope : Scope
@property (nonatomic, strong) NSArray *scopeElements;
@end
@interface CustomScope : Scope
@property (nonatomic, strong) NSArray *customizations;
@end
BasicScope有scopeElements,包括:
@interface Element : NSObject
@end
@interface ScopeElement : Element
@propery (nonatomic, assign) BOOL enabled;
@propery (nonatomic, assign) NSString *name;
@propery (nonatomic, assign) NSInteger priority;
@end
答案 0 :(得分:0)
scopes
数组的每个元素都需要具有属性name
。您的Scope
对象未声明名称属性。