NSMutableArray enumerateObjectsUsingBlock不是同步的,苹果说 [英] NSMutableArray enumerateObjectsUsingBlock is not synchronous as Apple says

查看:1286
本文介绍了NSMutableArray enumerateObjectsUsingBlock不是同步的,苹果说的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是错误吗?

我有这样的行:

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

     NSLog(@"%d", idx);
}];

NSLog(@"end");

这应该打印

"0"
"1"
"2"
...
"end"

但它正在打印

"end"
"0"
"1"
"2"
...

Apple说 enumerateObjectsWithOptions:usingBlock:是同步的,因此在枚举之前不应该打印end,对吗?

Apple says enumerateObjectsWithOptions:usingBlock: is synchronous, so "end" should not be printed before the enumeration, right?

你能确认吗?

推荐答案

enumerateObjectsUsingBlock:肯定是同步的。我只是在CodeRunner中运行相同的示例:

enumerateObjectsUsingBlock: is definitely synchronous. I just ran the same example in CodeRunner:

NSArray *myArray = @[ @1, @2, @3, @4, @5 ];
[myArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    NSLog(@"%d", idx);
}];

NSLog(@"end");

得到以下输出:

0
1
2
3 
4
end

这篇关于NSMutableArray enumerateObjectsUsingBlock不是同步的,苹果说的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆