且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在快速枚举中跟踪索引

更新时间:2022-05-28 21:50:33

a href =http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html> NSArray ,您将看到方法

Look at the API for NSArray and you will see the method

- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block

所以一试一试

[savedArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

    //... Do your usual stuff here

    obj  // This is the current object
    idx  // This is the index of the current object
    stop // Set this to true if you want to stop

}];