So, I have this:
@interface Foo
@property(nonatomic, readonly, retain) NSArray* bars;
@end
@implementation Foo
@synthesize bars = _bars;
// ... more stuff here ...
@end
So Foo fills up bars with instances of Bar, and the instance of Foo lives in a container object. And then I say:
[container valueForKeyPath:@"foo.bars.@count"]
Which I expect to give me a nice boxed number. However I instead get:
Exception: [<Bar 0xc175b70> valueForUndefinedKey:]: this class is not key value coding-compliant for the key bars.
So, why? I wouldn’t expect to have to implement anything special on Bar to make an NSArray of Bars countable, but that’s what this error message is implying. The documentation only has trivial examples, but I would expect this to just work in the same manner.
How does my code differ from yours? Because this works…
Then, in my container class:
Logs => “count is 2”