How does my code differ from yours? Because this works...
// Foo.h
#import <Foundation/Foundation.h>
@interface Foo : NSObject
@property(nonatomic, readonly, retain) NSArray* bars;
@end
// Foo.m
#import "Foo.h"
@interface Foo ()
// extended property decl here, to be readable, but this didn't seem to matter in my test
@property(nonatomic, retain) NSArray* bars;
@end
@implementation Foo
- (id)init {
self = [super init];
if (self) {
_bars = [NSArray arrayWithObjects:@"bar one", @"bar none", nil];
}
return self;
}
@end
Then, in my container class:
// .h
@property (strong, nonatomic) Foo *foo;
// .m
_foo = [[Foo alloc] init];
NSNumber *c = [self valueForKeyPath:@"foo.bars.@count"];
NSLog(@"count is %@", c);
Logs => "count is 2"