Reputation: 9243
I'm trying to use KVC collection to get the average count of arrays in a collection. In other words, my data structure looks like this @[ @[...], @[......], @[..] ]
and I am trying to average the count of the internal arrays.
I could do it the old fashion way, but it seems like something KVC collection operators might be able to help with -- unfortunately i can't get it to work.
It seems like this would be the right syntax:
NSNumber *avg = [topLevelArray valueForKeyPath:@"@avg.count"]
Yet this draws an exception -- claiming that the objects contained within the second level of arrays are not KVC compliant for the key 'count'.
Is there a way to run KVC collection operators on second level arrays?
Upvotes: 0
Views: 174
Reputation: 80273
Simply use the proper @count
collection operator [tested]:
NSNumber *avg = [topLevelArray valueForKeyPath:@"@avg.@count"];
Upvotes: 2