Skip to content

Instantly share code, notes, and snippets.

@cacaodev
Created December 19, 2010 20:29
Show Gist options
  • Save cacaodev/747664 to your computer and use it in GitHub Desktop.
Save cacaodev/747664 to your computer and use it in GitHub Desktop.
Return a KVC proxy if the receiver implements -countOfKey AND objectInKeyAtIndex:
- (id)valueForKey:(CPString)aKey
{
var capitalizedKey = aKey.charAt(0).toUpperCase() + aKey.substring(1),
objectAtIndexSEL = sel_getName(@"objectIn" + capitalizedKey + "AtIndex:"),
objectsAtIndexesSEL = sel_getName(aKey + "AtIndexes:"),
countSEL = sel_getName(@"countOf" + capitalizedKey);
if ([destination respondsToSelector:countSEL] && ([destination respondsToSelector:objectAtIndexSEL] || [destination respondsToSelector:objectsAtIndexesSEL]))
return [destination mutableArrayValueForKey:aKey];
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment