NSArray NSDictionary排序

遍历
  1. for( id *obj in array )
  2. enumerateObjectsUsingBlock:^(){}
  3. NSEnumerator *
排序
  • NSArray /
  • NSArray< NSDictionary * > /
  • NSArray< ObjectType *>

不同的模式下,根据自己 ModelType 选择自定义或者系统排序处理;

< 1 >

    [array1 sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        return [obj1 compare:obj2]; 
    }];

< 2 >

    NSSortStable 串行操作稳定效率偏低;NSSortConcurrent 并行操作效率高,适合排序大规模数据;
    排序结果无异议!!!
    [array2 sortedArrayWithOptions:NSSortStable usingComparator:^NSComparisonResult(id obj1, id obj2){
     //sort in id-type
      int ,string ...
            }];

< 3 > 都是自定义不同的类型对比方法来进行排序;

    sortedArrayUsingFunction 
    sortedArrayUsingSelector

< 4 > NSSortDescriptor

      NSSortDescriptor *brandDescriptor = [[NSSortDescriptor alloc] initWithKey:@"xxx" ascending:YES];
      NSArray *sortDescriptors = [NSArray arrayWithObject:brandDescriptor];
     self.AllModelArray = [MyModelArray sortedArrayUsingDescriptors:sortDescriptors];

objectType 是字典或者自定义的Model,因为对于配置等处理结果都是无序的列表;
所以需要根据属性类型进行排序处理。 等;

More ->Search

NSPredicate

    NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"name beginswith[c] %@", filterString];
    self.visibleResults = [self.AllModelArray filteredArrayUsingPredicate:filterPredicate];

.........

你可能感兴趣的:(NSArray NSDictionary排序)