object-c - 排序
(2014-02-17 10:59:04)
标签:
object-c-排序it |
分类: Mac/IOS那些事 |
排序
数字排序
_array = [[
NSMutableArray
alloc
]
initWithObjects
:
@"4"
,
@"1"
,
@"10"
,
@"2"
,
nil
];
_array = [[
NSMutableArray
alloc
]
initWithArray
:[_array
sortedArrayUsingComparator
:^NSComparisonResult(
id
obj
1
,
id
obj
2
)
{
return
[obj
1
compare
:obj
2
options
:NSNumericSearch];
}]];
升序 字母
_array = [[
NSMutableArray
alloc
]
initWithArray
:[_array
sortedArrayUsingSelector
:
@selector
(compare:)]];
//
_allKeys = [[
NSMutableArray
alloc
]initWithArray:[
self
.dict
allKeys
]];
//升序排序
_allKeys
= [[
NSMutableArray
alloc
]initWithArray:[_allKeys
sortedArrayUsingSelector
:
@selector
(compare:)]];
_allKeys
= [[
NSMutableArray
alloc
]initWithArray:[_allKeys
sortedArrayUsingComparator
:^NSComparisonResult(
id
obj
1
,
id
obj
2
)
{
return
[obj
1
compare
:obj
2
options
:NSNumericSearch]
==
NSOrderedAscending
;
}]];
前一篇:IOS - 常用开发Tips