该方法enumerateAttributesInRange
获取一个代码块并为其中的每个属性执行它NSAttributedString
- 它会异步调用 bock 吗?
当我的应用程序冻结后,以下方法连续调用两次真的很快 1,我想知道这是因为 enumerateAttributesInRange 异步运行代码块,所以 2 个线程正在尝试同时修改我的 AttributedString。
- (void) doSomething
{
//following line works fine
[self doSomethingwithAttributedString];
//following line works fine
[self doSomethingwithAttributedString];
[self performSelector:@selector(doSomethingwithAttributedString) withObject:nil afterDelay:1];
//following crashes
[self doSomethingwithAttributedString];
[self doSomethingwithAttributedString];
}
- (void)doSomethingwithAttributedString
{
[self.attributedString enumerateAttributesInRange:_selectedRange options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:
^(NSDictionary *attributes, NSRange range, BOOL *stop) {
// Here I modify the dictionary and add it back to my attributedString
}];
}