How to indicate index of NSIndexSet object?

六月ゝ 毕业季﹏ 提交于 2019-12-11 05:09:26

问题


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 ?]);

回答1:


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

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



回答2:


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]);
}];


来源:https://stackoverflow.com/questions/6885106/how-to-indicate-index-of-nsindexset-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!