クラス A オブジェクトの配列があります。これを detailsArray とします。
クラス A にはプロパティとして日付、名前があります。
日付に基づいてこの配列をソートする良い方法を提案できる人はいますか?
NSSortDescriptor
この配列をソートするにはどうすればよいですか? NSSortDescriptor
私は...を使用して辞書の配列をソートすることを知っています
どんな助けでも大歓迎です.....
クラス A オブジェクトの配列があります。これを detailsArray とします。
クラス A にはプロパティとして日付、名前があります。
日付に基づいてこの配列をソートする良い方法を提案できる人はいますか?
NSSortDescriptor
この配列をソートするにはどうすればよいですか? NSSortDescriptor
私は...を使用して辞書の配列をソートすることを知っています
どんな助けでも大歓迎です.....
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:NO];
NSArray *sortedArray = [detailsArray sortedArrayUsingDescriptors:@[sortDescriptor]];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"self" ascending:NO];
NSArray *descriptors = [NSArray arrayWithObject: descriptor];
NSArray *reverseOrder = [dateArray sortedArrayUsingDescriptors:descriptors];
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"date"
ascending:YES] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray;
sortedArray = [yourArray sortedArrayUsingDescriptors:sortDescriptors];
または、ブロックも使用できます
NSArray *sortedArray;
sortedArray = [yourArray sortedArrayUsingComparator:^NSComparisonResult(A *a, A *b) {
NSDate *first = a.date;
NSDate *second = b.date;
return [first compare:second];
}];
次のように、クラス名でキーを転送する必要があります
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"ClassA.date" ascending:YES];
質問する前にクエリをグーグルで検索し、グーグルクローラーの結果を参照してください。