我如何在这样的块内的[index]
处获取对象?目的是为了获得第一个字母并按字典顺序对NSDictionaries数组进行排序。
NSArray *sortedArray;
sortedArray = [_photos sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
NSString *first = _photos[0][FLICKR_PHOTO_TITLE];
NSString *second = _photos[0][FLICKR_PHOTO_TITLE];
return [first compare:second];
}];
_photos = sortedArray;
最佳答案
看来您有一系列字典。要对FLICKR_PHOTO_TITLE
键的值进行排序,请执行以下操作:
_photos = [_photos sortedArrayUsingComparator:^NSComparisonResult(NSDictionary *a, NSDictionary *b) {
NSString *first = a[FLICKR_PHOTO_TITLE];
NSString *second = b[FLICKR_PHOTO_TITLE];
return [first compare:second];
}];