メソッドenumerateAttributesInRange
はコードのブロックを取得し、すべての属性に対してそれを実行しますNSAttributedString
- ブロックを非同期で呼び出しますか?
次のメソッドが 2 回続けて呼び出されると、アプリがフリーズした後、非常に迅速に 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
}];
}