App crashes often in a for-loop
- by Flocked
Hello,
my app crashes often in this for-loop:
for (int a = 0; a <= 20; a++) {
int b = arc4random() % [newsStories count];
NSString * foo = [[NSString alloc]initWithString:[[newsStories objectAtIndex: arc4random() % b]objectForKey:@"title"]];
foo = [foo stringByReplacingOccurrencesOfString:@"’" withString:@""];
foo = [[foo componentsSeparatedByCharactersInSet:[[NSCharacterSet letterCharacterSet] invertedSet]] componentsJoinedByString:@" "];
foo = [foo stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
textView.text = [textView.text stringByAppendingString:[NSString stringWithFormat:@"%@ ", foo]];
}
The code changes a NSString from a NSDictionary and adds it into a textView. Sometimes it first crashes in the second time using the for-loop. What did I wrong?