//数组排序 第一个变量为要排序的关键字 第二个变量为是否是升序
-(void)startArraySort:(NSString *)keystring isAscending:(BOOL)isAscending
{
//self.destinationArry=[[NSMutableArray alloc]init];
NSSortDescriptor* sortByA = [NSSortDescriptor sortDescriptorWithKey:keystring ascending:isAscending];
//[ self.sourceArry sortUsingDescriptors:[NSArray arrayWithObject:sortByA]];
//destinationArry 排序后的数组 sourceArry 源数据
self.contactArray=[[NSMutableArray alloc]initWithArray:[self.tempArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortByA]]];
for (CompanyContactEntity *contactEntity in _contactArray) {
NSLog(@"category是%@",contactEntity.category);
}
}
使用:
[self startArraySort:@"category" isAscending:YES];