2 ms·
Another approach: @interface NSDictionary (objectForKeyList) - (id)objectForKeyList:(id)key, ...; @end @implementation NSDictionary (objectFor
by mayoff 15y ago
Another approach:
@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;
}
@end
- terhechte 15y agoAlso a good idea, thanks for sharing. This could even be expanded to check whether list items are integers and call objectAtIndex: instead in order to traverse Array/Dictionary mixups.