- (NSArray *)sortedArrayUsingSelector:(SEL)comparator
Parameters
comparator
A selector that identifies the method to use to compare two elements at a time. The method should returnNSOrderedAscending
if the receiver is smaller than the argument, NSOrderedDescending
if the receiver is larger than the argument, and NSOrderedSame
if they are equal
NSArray *sortedArray =
|
[anArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
|
@property (nonatomic,readwrite, retain) NSMutableArray *parameters;
[self.parameterssortUsingSelector:@selector(compare:)];
#pragma mark -
- (NSComparisonResult)compare:(id)inObject {
NSComparisonResult result = [self.namecompare:[(MPURLRequestParameter *)inObjectname]];
if (result ==NSOrderedSame) {
result = [self.valuecompare:[(MPURLRequestParameter *)inObjectvalue]];
}
return result;
}
//////////////////////////////////////////////////////////
sortedArrayUsingFunction:适合基本类型(支持compare方法)
#pragma mark SORT METHOTDS
NSInteger sortObjectsByLatestTime(id obj1,id obj2, void *context)
{
NSDate* d1 = [(MessageGroup*)obj1latestTime];
NSDate* d2 = [(MessageGroup*)obj2latestTime];
//sort by desc
return [d2compare:d1];
}
NSInteger dateSort(id obj1,id obj2, void *context)
{
NSDate* d1 = ((Inbox*)obj1).datetime;
NSDate* d2 = ((Inbox*)obj2).datetime;
return [d1compare:d2];
}
////////////////////////////////////////////////////////////////////
-(NSArray*)sortedMessages
{
return [[groupMessagesallValues] sortedArrayUsingFunction:sortObjectsByLatestTimecontext:NULL];
}
//////////////////////////////////////////////////////////
sortUsingDescriptors:适合元素是dict类型,initWithKey既是dict key.
NSMutableArray *regions = [NSMutableArrayarray];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptoralloc] initWithKey:@"name"ascending:YES];
NSArray *sortDescriptors = [NSArrayarrayWithObject:sortDescriptor];
[regionssortUsingDescriptors:sortDescriptors];
[sortDescriptor release];
相关推荐
NSArray排序demo
使用数据结构的排序算法,对NSArray进行排序,包括快速、选择、插入、希尔等四种排序算法
NSArray *arr = [[NSArray alloc] initWithObjects:如果要初始化1000项,可以这样:当然换成swift就超级简单了
Object C 字符串和数组NSString NSArray操作
官方文档,数组类的最权威文档。各种数组方法的详细说明。英文的。
NSString NSArray NSDictionary 方法名释义
比较完美的解决了数组越界的问题, 在debug模式下会崩溃 , 在release不会崩溃 , 开发过程中 , 方便调试 , 正式环境中 减少崩溃.
Swift-NSArray数组的使用
Iphone数组一些基础操作 NSArray/NSMutableArrayIphone
OC-NSArray数组的使用Demol
1. 数组的常用处理方式 //--------------------不可变数组 //1....NSString *s1 = @zhangsan; NSString *s2 = @lisi; NSString *s3 = @wangwu;...NSArray *array1 = [[NSArray ...NSArray *array2 = [NSArray arrayWithOb
NSPredicate应用,包括以下几个部分: 1、字符串,正则表达式的匹配; 2、字符串数组NSArray和NSMutableArray的快捷过滤方式; 3、自定义对象数组NSArray和NSMutableArray的快捷过滤方式;
主要介绍了IOS 开发之 NSMutableArray与NSArray 的区别的相关资料,希望通过本文能掌握这部分内容,需要的朋友可以参考下
NSArray,NSSet,NSEnumerator,NSDictionary及对应Mutable介绍,有对应的实例代码
一些NSArray,NSDictionary,NSSet相关的算法知识1
Objective-C的数组比C++,Java的数组强大在于,NSArray保存的对象可以是不同的对象。但只能保存对象,int ,char,double等基本数据类型不能直接保存,需要通过转换成对象才能加入数组。
详细的说明和用法 NSArray,NSSet,NSDictionary 以及他们子类的说明
NSArray-Shuffle 用于混洗数组的 NSArray 类别。方法bjl_shuffledArray - ( NSArray *)bjl_shuffledArray 返回值返回一个数组,其中所有元素都被随机排列。 bjl_shuffledArrayWithItemLimit: - ( NSArray *)bjl_...
object-c 适合初学者,主要学习数组,包括固定数组和可变数组,以及创建简单类文件和使用方法
NSArray+FunctionalHelper 在使用了 Linq、Underscore.js 和 ActiveRecord 等框架之后,我们习惯了许多为集合提供的方法。 我们没有继续在没有它们的情况下生活,而是自己写了一些。 每个返回NSArray或NSSet都会...