38+ (id) filterEnumerator:(NSEnumerator *)enumerator withSelector:(
SEL)selector
40 if (selector == NULL)
return [[enumerator retain] autorelease];
42 return [[[
self alloc] initWithUnderlyingEnumerator:enumerator
50+ (id) filterEnumerator:(NSEnumerator *)enumerator withSelector:(
SEL)selector andArgument:(
id)argument
52 if (selector == NULL)
return [[enumerator retain] autorelease];
54 return [[[
self alloc] initWithUnderlyingEnumerator:enumerator
57 argumentValue:argument]
61- (id) initWithUnderlyingEnumerator:(NSEnumerator *)enumerator
62 withSelector:(
SEL)selector
63 takingArgument:(BOOL)takesArgument
64 argumentValue:(
id)argument
83 [_underlyingEnum release];
92 NSString *subDesc = NSStringFromSelector(
_selector);
95 subDesc = [subDesc stringByAppendingString:[_argument shortDescription]];
98 return [NSString stringWithFormat:@"%@ matching %@", [_underlyingEnum shortDescription], subDesc];
113 id obj = [_underlyingEnum nextObject];
121 [_underlyingEnum release];
130 IMP predicate = [obj methodForSelector:_selector];
131 if (predicate != NULL)
149 if (filter)
return obj;
156@implementation NSEnumerator (OOFilteringEnumerator)
158- (id) filteredWithSelector:(
SEL)selector
164- (id) filteredWithSelector:(
SEL)selector andArgument:(
id)argument
172@implementation NSArray (OOFilteringEnumerator)
174- (id) objectEnumeratorFilteredWithSelector:(
SEL)selector
176 return [[
self objectEnumerator] filteredWithSelector:selector];
180- (id) objectEnumeratorFilteredWithSelector:(
SEL)selector andArgument:(
id)argument
182 return [[
self objectEnumerator] filteredWithSelector:selector andArgument:argument];
188@implementation NSSet (OOFilteringEnumerator)
190- (id) objectEnumeratorFilteredWithSelector:(
SEL)selector
192 return [[
self objectEnumerator] filteredWithSelector:selector];
196- (id) objectEnumeratorFilteredWithSelector:(
SEL)selector andArgument:(
id)argument
198 return [[
self objectEnumerator] filteredWithSelector:selector andArgument:argument];
204@implementation NSDictionary (OOFilteringEnumerator)
206- (id) objectEnumeratorFilteredWithSelector:(
SEL)selector
208 return [[
self objectEnumerator] filteredWithSelector:selector];
212- (id) objectEnumeratorFilteredWithSelector:(
SEL)selector andArgument:(
id)argument
214 return [[
self objectEnumerator] filteredWithSelector:selector andArgument:argument];
218- (id) keyEnumeratorFilteredWithSelector:(
SEL)selector
220 return [[
self keyEnumerator] filteredWithSelector:selector];
224- (id) keyEnumeratorFilteredWithSelector:(
SEL)selector andArgument:(
id)argument
226 return [[
self keyEnumerator] filteredWithSelector:selector andArgument:argument];
232@implementation NSEnumerator (OOMakeObjectsPerformSelector)
234- (void)makeObjectsPerformSelector:(
SEL)selector
237 while ((
object = [
self nextObject]))
239 if (selector != NULL && [
object respondsToSelector:selector])
241 [object performSelector:selector];
247- (void)makeObjectsPerformSelector:(
SEL)selector withObject:(
id)argument
250 while ((
object = [
self nextObject]))
252 if (selector != NULL && [
object respondsToSelector:selector])
254 [object performSelector:selector withObject:argument];
BOOL(* BoolReturnMsgSend)(id, SEL)
BOOL(* BoolReturnWithParamMsgSend)(id, SEL, id)
NSEnumerator * _underlyingEnum
id filterEnumerator:withSelector:(NSEnumerator *enumerator,[withSelector] SEL selector)
id filterEnumerator:withSelector:andArgument:(NSEnumerator *enumerator,[withSelector] SEL selector,[andArgument] id argument)
NSString * descriptionComponents()
NSString * shortDescriptionComponents()