la méthode enumerateAttributesInRange
obtient un bloc de code et l'exécute pour chaque attribut dans NSAttributedString
NSAttributedString - enumerateAttributesInRange provoque un crash?
- -t-il appeler le bock de manière asynchrone?
Lorsque la méthode suivante est appelée deux fois de suite vraiment rapide 1 après la othr mon application se fige, je me demande de c'est parce que enumerateAttributesInRange dirige le bloc de code en mode asynchrone, donc 2 fils tentent de modifier mon AttributedString en même temps.
- (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
}];
}
N'oubliez pas non plus de tester la clé du dictionnaire pour un objet nul. – Stuart