I have three arrays:
NSArray *Q = [1+1, 2+2, 3+3, 4+4, 5+5];
NSArray *A = [2, 4, 6, 8, 10];
NSArray *UserAnswers = [2, 4, 10, 17, 26];
In a tableview I want to show the results but the wrong answers(in this case 10,17,26) must be shown before the correct answers(At top of the tableView).
I post it here because I need a clean and smart solution to solve this. Any ideas?
this is the dirty way, Anyone know an easier/cleaner way?
NSMutableArray *wrongs = [NSMutableArray new];
NSMutableArray *rights = [NSMutableArray new];
NSMutableArray *dataSource = [NSMutableArray new];
for (int x = 0; x<questions.count; x++) {
NSDictionary *temp = [[NSDictionary alloc]initWithObjectsAndKeys:[questions objectAtIndex:x],@"q",[answers objectAtIndex:x],@"a",[userAnswers objectAtIndex:x], "ua", nil];
if ([[userAnswers objectAtIndex:x]isEqual:[answers objectAtIndex:x]])
[rights addObject:temp];
else
[wrongs addObject:temp];
}
[dataSource addObjectsFromArray:wrongs];
[dataSource addObjectsFromArray:rights];
[wrongs release];
[rights release];
From comments
Your way looks reasonably clean; perhaps add answers to the correct arrays as the user answers?