我使用NSMutableArray(listId)
制作dictionaries(dizionario)
(通过调用sqlite数据库):
-(void)readItems {
NSString * query = @"SELECT * FROM item";
NSArray * arrayQuery = [[NSArray alloc] initWithObjects:@"id",@"title",@"note",@"icon",@"perc",@"complete",nil];
NSArray * arrayEle = [self caricaValoriDaDBStandard:query :arrayQuery];
for (int i = 0; i < [arrayEle count]; i++)
{
NSMutableDictionary *dizionario = [arrayEle objectAtIndex:i];
[listId addObject:dizionario];
}
}
如何对数组进行排序,例如“id”键?
答案 0 :(得分:3)
您可以使用以下代码:
NSArray sortedArray = [listId sortedArrayUsingComparator: ^(id a, id b) {
NSString *first = [a objectForKey:@"id"];
NSString *second = [b objectForKey:@"id"];
return [first compare:second];
}];