0

如何在这样[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;
4

1 回答 1

2

看来您有一系列字典。要对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];
}];
于 2013-03-10T19:22:17.087 回答