私が得ているエラーは
Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CALayerArray: 0x7c85080> was mutated while being enumerated.'
私が理解しNSGenericException
ているのは、列挙中に配列から何かを削除しているということです。それでもそれを知って周りを見回すと、私の問題を解決できないようです。これが以下のコードです。
-(void)tableView(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//Checks if message has been read. If message has not it updates the unreadMessages array
if ([unreadMessage containsObject:[NSString stringWithFormat:@"m%@",[[storage_array objectAtIndex:indexPath.row] objectForKey:@"id"]]] == TRUE && [[[storage_array objectAtIndex:indexPath.row] objectForKey:@"itemtype"] isEqualToString:@"message"] == TRUE){
//Unread
[unreadMessage removeObject:[NSString stringWithFormat:@"m%@",[[storage_array objectAtIndex:indexPath.row] objectForKey:@"id"]]];
[unreadMessage writeToFile:[self saveUnreadMessages] atomically:YES];
//Read
[readMessage addObject:[NSString stringWithFormat:@"m%@",[[storage_array objectAtIndex:indexPath.row] objectForKey:@"id"]]];
[readMessage writeToFile:[self saveReadMessages] atomically:YES];
[tableView reloadData];
}
else if ([unreadNewsletter containsObject:[NSString stringWithFormat:@"n%@",[[storage_array objectAtIndex:indexPath.row] objectForKey:@"id"]]] == TRUE && [[[storage_array objectAtIndex:indexPath.row] objectForKey:@"itemtype"] isEqualToString:@"newsletter"] == TRUE){
//Unread
[unreadNewsletter removeObject:[NSString stringWithFormat:@"n%@",[[storage_array objectAtIndex:indexPath.row] objectForKey:@"id"]]];
[unreadNewsletter writeToFile:[self saveUnreadNewsletters] atomically:YES];
//Read
[readNewsletter addObject:[NSString stringWithFormat:@"n%@",[[storage_array objectAtIndex:indexPath.row] objectForKey:@"id"]]];
[readNewsletter writeToFile:[self saveReadNewsletters] atomically:YES];
[tableView reloadData];
}
}