我遍历iOS设备上的相册列表。在迭代完这个小组后,我想简单地打印出找到的专辑数量。
在我的代码中,我必须更改NSLog
语句仅在所有相册都已加载时执行。
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
void (^groupBlock)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop){
if (group == nil){return;}
[tempArray addObject:group];
};
void (^failureBlock)(NSError *) = ^(NSError *error) {
NSLog(@"A problem occured %@", [error description]);
};
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:groupBlock
failureBlock:failureBlock];
NSLog(@"%i albums were loaded", tempArray.count);
答案 0 :(得分:5)
点名完成后,您的groupBlock
会收到一组nil
,因此请更改:
if (group == nil){return;}
到
NSLog(@"%i albums were loaded", tempArray.count);
来自班级参考:
枚举完成后,调用 enumerationBlock 并将组设置为
nil
。