Fast NSDictionary traversal in Objective-C
appventure.me
appventure.me
@interface NSDictionary (objectForKeyList)
- (id)objectForKeyList:(id)key, ...;
@end
@implementation NSDictionary (objectForKeyList)
- (id)objectForKeyList:(id)key, ...
{
id object = self;
va_list ap;
va_start(ap, key);
for ( ; key; key = va_arg(ap, id))
object = [object objectForKey:key];
va_end(ap);
return object;
}
@endI think the category approach is much better (cleaner, easier documented, conventional) and there really isn't a speed increase in using the preprocessor (anything that looks like a difference in time is due to either caching or CPU load at the time).