找出我的异步调用何时完成
我遍历 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);
I iterate through a list of photo albums on a iOS device. After having iterated through this group I want to simply print out the number of albums that were found.
What do I have to change in my code that the NSLog
statement is only executed, when all the albums were loaded.
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
枚举完成后,您的
groupBlock
将收到一组nil
,因此将:更改为
From the Class引用:
[来源]
Your
groupBlock
will receive a group ofnil
when the enumeration is completed, so change:to
From the Class reference:
[source]