On Nov 21, 2008, at 8:44 AM, David Blanton wrote:

How would one construct an NSIndexSet containing the indices 2,4,5 ?

I did:

        NSRange two = NSMakeRange(2, 1);
        NSRange four = NSMakeRange(4, 1);
        NSRange five = NSMakeRange(5, 1);
        NSRange u1 = NSUnionRange(two,four);
        NSRange u2 = NSUnionRange(u1,five);
        id indices = [NSIndexSet indexSetWithIndexesInRange:u2];
But, of course, NSUnionRange adds 3 so indices becomes 2,3,4,5.

Use an NSMutableIndexSet:

NSRange range = NSMakeRange(2, 4);
NSMutableIndexSet *mutSet = [[NSMutableIndexSet alloc] initWithIndexesInRange:range];
[mutSet removeIndex:3];

And if for some reason you really need it as a non-mutable version:

NSIndexSet *set = [[NSIndexSet alloc] initWithIndexSet:set];


Compiled in Mail.app; caveat emptor.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to