美文网首页
iOS中数组对象按照对象的一个字段进行排序

iOS中数组对象按照对象的一个字段进行排序

作者: 乡村小子 | 来源:发表于2016-10-28 17:22 被阅读0次

NSMutableArray *commentListArray=[[NSMutableArray alloca]init];

// 为每个属性创建NSSortDescriptor对象,并确定为升序

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"commentId" ascending:YES];//

// 设置排序优先级,并组成数组。这里优先级最高为commentId

NSArray * sortDescriptors =  [[NSArray alloc] initWithObjects:&sortDescriptor count:1];

[commentListArray sortUsingDescriptors:sortDescriptors];

// 为数组中每个元素执行方法,输出状态

[commentListArray makeObjectsPerformSelector:@selector(printState)];

相关文章

网友评论

      本文标题:iOS中数组对象按照对象的一个字段进行排序

      本文链接:https://www.haomeiwen.com/subject/uaseuttx.html