NSIndexSet to NSArray

How can I transfer the values in an NSIndexSet to a NSArray in ApplescriptObjC and/or in Objective-C.
I have the following category that is called from ApplescriptObjc as follow:


	on testallIndexes_(sender)
		set thearray to current application's NSArray's arrayWithArray_({"<egBarcL:barcodes>","<rdf:Bag>"," <rdf:li rdf:parseType=\"Resource\">"," </rdf:Bag>"," </egBarcL:barcodes>","<egBarcL:barcodes>","<rdf:Bag>"," <rdf:li rdf:parseType=\"Resource\">"," </rdf:Bag>"," </egBarcL:barcodes>"})

		set theIndexes to  thearray's allIndexes_("<egBarcL:barcodes>")
		log theIndexes
	end

the result is :
<NSIndexSet: 0x10012d5c0>[number of indexes: 2 (in 2 ranges), indexes: (0 5)]

The category is as follows:


#import <Foundation/Foundation.h>
@interface NSArray (indexOfArrayObjects)
- (NSIndexSet *) allIndexes: (NSString*) searchString;
@end
------------------------------------------------

#import "NSObject+indexOfArrayObjects.h"

@implementation NSArray (indexOfArrayObjects)
- (NSIndexSet *) allIndexes: (NSString*) searchString
{
    NSArray *weakSelf = [self copy];	
    NSIndexSet *indexes = [weakSelf indexesOfObjectsPassingTest:^ BOOL (id obj, NSUInteger idx, BOOL *stop) {
		NSRange range = [obj rangeOfString : searchString];
		BOOL found = ( range.location != NSNotFound );
		if (found)
		{
			return YES;}
		else
		{
			return NO;};
	}];
	return indexes;
}
@end

I need the indexes as an array because i want to use them in ApplescriptOBjc to locate different parts in the original array.

Hi,

you could add a second method to your category


- (NSMutableArray *)allIndexesArray: (NSString *)searchString
{
NSArray *weakSelf = [self copy];
NSMutableArray *result = [NSMutableArray array];    
[weakSelf enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        NSRange range = [obj rangeOfString : searchString];
        BOOL found = ( range.location != NSNotFound );
        if (found)
            [result addObject:[NSNumber numberWithUnsignedInteger:idx]];
    }];
   return result;
}

Thanks Stefan, it works like a charm.
Is there a solution also to get an array from NSIndexSets in ApplesciptObjc for curiosity my curiosity only.)

assuming the variable indexSet is an instance of NSMutableIndexSet


 set resultArray to {}
 set notFound to current application's NSNotFound
        repeat until indexSet's firstIndex() is notFound
        set end of resultArray to indexSet's firstIndex()
        indexSet's removeIndex_(indexSet's firstIndex())
 end
 log resultArray

Thanks Stefan for this super fast answer. I’m going to test all this stuff.