Closed huguesbr closed 10 years ago
@huguesbr thanks for the contribution.
This already exists in objc - it's called valueForKeyPath:
.
So you can write this as:
// your example
[[[sampleArray mapSelector:@selector(uppercaseString)] should] equal:@[ @"FIRST", @"SECOND", @"THIRD" ]];
// builtin
[[[sampleArray valueForKeyPath:@"uppercaseString"] should] equal:@[ @"FIRST", @"SECOND", @"THIRD" ]];
haha, yes I realize this just after pushing. I wasn't sure that kvc will work as flexible as a selector, which we could extend using [array mapSelector:@selector(compare:) withObject:x]
@huguesbr in that case it doesn't make sense anymore to stringly type, the block version is more explicit and readable
Adding mapSelector:(SEL)selector which perform the selector on each object (behave like map(&:something) in ruby)