开发者

How to indicate index of NSIndexSet object?

开发者 https://www.devze.com 2023-03-23 20:25 出处:网络
everyone. I want to indicate index of NSIndexSet object. Find various method but I can\'t find. How to indicate index of NSIndexSet object?

everyone.

I want to indicate index of NSIndexSet object.

Find various method but I can't find.

How to indicate index of NSIndexSet object?

NSMutableArray *array = [[NSMutableArray alloc]initWithObjects:@"A",@"B",@"C",@"A", nil];

NSIndexSet *indexset = [array indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL开发者_高级运维 *stop) {
    return [obj isEqual:@"A"];
}];

NSLog(@"%@",[array objectsAtIndexes:indexset]);

// I want to indicate index of NSIndexSet object.
NSLog(@"%d",[indexset ?]);


If you want to get number of indices stored in NSIndexSet then use count property:

NSLog(@"%d",[indexset count]);


From, iOS 4.0 and > there's few method which enumerates the NSIndexSet, here's the one which answering to this question, - (void)enumerateIndexesUsingBlock:(void (^)(NSUInteger idx, BOOL *stop))block

[indexset enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
    NSLog(@"%d=>%@",idx,[array objectAtIndex:idx]);
}];
0

精彩评论

暂无评论...
验证码 换一张
取 消