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.