diff --git a/Headers/Foundation/NSArray.h b/Headers/Foundation/NSArray.h index cfa6f8d8b..75467822c 100644 --- a/Headers/Foundation/NSArray.h +++ b/Headers/Foundation/NSArray.h @@ -29,6 +29,7 @@ #import #import #import +#import #if defined(__cplusplus) extern "C" { @@ -115,6 +116,14 @@ extern "C" { - (BOOL) writeToURL: (NSURL*)url atomically: (BOOL)useAuxiliaryFile; - (id) valueForKey: (NSString*)key; #endif +DEFINE_BLOCK_TYPE(GSEnumeratorBlock, void, id, NSUInteger, BOOL*); +/** + * Enumerate over the collection using the given block. The first argument is + * the object and the second is the index in the array. The final argument is + * a pointer to a BOOL indicating whether the enumeration should stop. Setting + * this to YES will interrupt the enumeration. + */ +- (void)enumerateObjectsUsingBlock: (GSEnumeratorBlock)aBlock; @end diff --git a/Source/GNUmakefile b/Source/GNUmakefile index 9a752e0b4..a98757b09 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -112,6 +112,7 @@ win32-def.top \ libgnustep-base.def ADD_HEADERS = \ +GSBlocks.h \ GSVersionMacros.h \ GSObjCRuntime.h \ GSCategories.h \ diff --git a/Source/NSArray.m b/Source/NSArray.m index 16de0b109..af9e8fb06 100644 --- a/Source/NSArray.m +++ b/Source/NSArray.m @@ -54,6 +54,7 @@ #import "Foundation/NSKeyedArchiver.h" #import "GNUstepBase/GSCategories.h" #import "GSPrivate.h" +#import "GSFastEnumeration.h" static BOOL GSMacOSXCompatiblePropertyLists(void) { @@ -1618,6 +1619,19 @@ compare(id elem1, id elem2, void* context) return result; } +- (void)enumerateObjectsUsingBlock: (GSEnumeratorBlock)aBlock +{ + NSUInteger count = 0; + BOOL shouldStop = NO; + FOR_IN (id, obj, self) + CALL_BLOCK(aBlock, obj, count++, &shouldStop); + if (shouldStop) + { + return; + } + END_FOR_IN(self) +} + @end