在包含在数组数组中的 class 中按名称查找 属性

Finding a property by name in a class that's contained in array of array

我有一个有点不平凡的包含层次结构,我想尝试使用 NSPredicate 来查找 scopes 列表中的任何元素 属性 称为 name 其值与我提供的匹配。当我构建谓词时,出现错误:

this class is not key value coding-compliant for the key 'name'

这是我的 class 结构的样子:

@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 class 组成,两者都派生自一个共同的 class:

@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

scopes 数组的每个元素都需要 属性 name。您的 Scope 对象未声明名称 属性。