Grouping of Custom Objects in Objective-C

前端 未结 6 1602
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 03:59

I have and array of custom objects of Person Class

Person : NSObject{
    NSString *firstName;
    NSString *lastName; 
    NSString *age;
}

NSMutableArray          


        
6条回答
  •  孤街浪徒
    2021-01-12 04:54

    A Drop in code to help you doing it,

        -(NSMutableArray *)sortArray:(NSArray *)arrayTosort withKey:(NSString *)key ascending:(BOOL)_ascending
    {
        NSSortDescriptor *sortDescriptor;
        sortDescriptor = [[NSSortDescriptor alloc] initWithKey:key
                                                     ascending:_ascending] ;
        NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
    
        return [[arrayTosort sortedArrayUsingDescriptors:sortDescriptors] mutableCopy];
    }
    

    here key is key or keypath.

提交回复
热议问题