iOS oc可变数组排序方法
2015-12-18 21:01
447 查看
1.首先定义可变数组
@property (nonatomic,strong)NSMutableArray * loadAllStylist;
-(NSMutableArray *)loadAllStylist{
if (!_loadAllStylist) {
_loadAllStylist = [NSMutableArrayarray];
}
return_loadAllStylist;
}
2.数据从数据库加载已转BloggerInfo模型类型
NSArray* stylists = [ModeDatabasereadDataFromTableName:BLOGGER_INFO_TABLE_NAMEwithConditionDictionary:nilcallbackClass:[NSArrayclass]];
if ([stylists
diffClassArray]) {
[self.loadAllStylistaddObjectsFromArray:stylists];
3.(重点排序)可变数组调用这个方法排序(默认升序):
[self.loadAllStylistsortUsingComparator:^NSComparisonResult(id _Nonnull
obj1, id _Nonnull obj2) {
BloggerInfo* b1 = obj1;
BloggerInfo* b2 = obj2;
return [b1.nicknamecompare:b2.nickname options:NSCaseInsensitiveSearch];//大小写不敏感的搜索
}];
4.一些可选参数
options:
typedef NS_OPTIONS(NSUInteger, NSStringCompareOptions) {
NSCaseInsensitiveSearch = 1, //大小写不敏感的搜索
NSLiteralSearch = 2,/* Exact character-by-character equivalence */
NSBackwardsSearch = 4,/* Search from end of source string */
NSAnchoredSearch = 8,/* Search is limited to start (or end, if NSBackwardsSearch) of source string */
NSNumericSearch = 64,/* Added in 10.2; Numbers within strings are compared using numeric value, that is, Foo2.txt
< Foo7.txt < Foo25.txt; only applies to compare methods, not find */
NSDiacriticInsensitiveSearch NS_ENUM_AVAILABLE(10_5,2_0)
= 128,
/* If specified, ignores diacritics (o-umlaut == o) */
NSWidthInsensitiveSearch NS_ENUM_AVAILABLE(10_5,2_0)
= 256,
/* If specified, ignores width differences ('a' == UFF41) */
NSForcedOrderingSearch NS_ENUM_AVAILABLE(10_5,2_0)
= 512,
/* If specified, comparisons are forced to return either NSOrderedAscending or NSOrderedDescending if the strings are equivalent but not strictly equal, for stability when sorting (e.g. "aaa" > "AAA" with NSCaseInsensitiveSearch specified) */
NSRegularExpressionSearch NS_ENUM_AVAILABLE(10_7,3_2)
= 1024
/* Applies to rangeOfString:..., stringByReplacingOccurrencesOfString:..., and replaceOccurrencesOfString:... methods only; the search string is treated as an ICU-compatible regular expression; if set, no other options can apply except NSCaseInsensitiveSearch
and NSAnchoredSearch */
};
@property (nonatomic,strong)NSMutableArray * loadAllStylist;
-(NSMutableArray *)loadAllStylist{
if (!_loadAllStylist) {
_loadAllStylist = [NSMutableArrayarray];
}
return_loadAllStylist;
}
2.数据从数据库加载已转BloggerInfo模型类型
NSArray* stylists = [ModeDatabasereadDataFromTableName:BLOGGER_INFO_TABLE_NAMEwithConditionDictionary:nilcallbackClass:[NSArrayclass]];
if ([stylists
diffClassArray]) {
[self.loadAllStylistaddObjectsFromArray:stylists];
3.(重点排序)可变数组调用这个方法排序(默认升序):
[self.loadAllStylistsortUsingComparator:^NSComparisonResult(id _Nonnull
obj1, id _Nonnull obj2) {
BloggerInfo* b1 = obj1;
BloggerInfo* b2 = obj2;
return [b1.nicknamecompare:b2.nickname options:NSCaseInsensitiveSearch];//大小写不敏感的搜索
}];
4.一些可选参数
options:
typedef NS_OPTIONS(NSUInteger, NSStringCompareOptions) {
NSCaseInsensitiveSearch = 1, //大小写不敏感的搜索
NSLiteralSearch = 2,/* Exact character-by-character equivalence */
NSBackwardsSearch = 4,/* Search from end of source string */
NSAnchoredSearch = 8,/* Search is limited to start (or end, if NSBackwardsSearch) of source string */
NSNumericSearch = 64,/* Added in 10.2; Numbers within strings are compared using numeric value, that is, Foo2.txt
< Foo7.txt < Foo25.txt; only applies to compare methods, not find */
NSDiacriticInsensitiveSearch NS_ENUM_AVAILABLE(10_5,2_0)
= 128,
/* If specified, ignores diacritics (o-umlaut == o) */
NSWidthInsensitiveSearch NS_ENUM_AVAILABLE(10_5,2_0)
= 256,
/* If specified, ignores width differences ('a' == UFF41) */
NSForcedOrderingSearch NS_ENUM_AVAILABLE(10_5,2_0)
= 512,
/* If specified, comparisons are forced to return either NSOrderedAscending or NSOrderedDescending if the strings are equivalent but not strictly equal, for stability when sorting (e.g. "aaa" > "AAA" with NSCaseInsensitiveSearch specified) */
NSRegularExpressionSearch NS_ENUM_AVAILABLE(10_7,3_2)
= 1024
/* Applies to rangeOfString:..., stringByReplacingOccurrencesOfString:..., and replaceOccurrencesOfString:... methods only; the search string is treated as an ICU-compatible regular expression; if set, no other options can apply except NSCaseInsensitiveSearch
and NSAnchoredSearch */
};
相关文章推荐
- iOS开发-使用Storyboard进行界面跳转及传值
- iOS程序的证书和签名机制
- iOS关于上传单张及多张图片
- radios组件
- iOS开发——使用delegate进行消息传递
- iOS 创建线程的多种方法
- ios学习----- mjRefresh使用指南
- iOS SDK:iOS调试技巧
- 利用pre平台实现iOS应用程序自动更新
- IOS NSString NSMutableString 不可变|可变字符串
- NSDate iOS 日期
- IOS设备设计完整指南
- iOS Xcode工程目录的 folder 和 group的区别(蓝色和黄色文件夹的区别)
- iOS拼接字符串
- iOS邮箱正则表达式
- iOS判断为空
- IOS高仿三九脑科医院综合查询系统-列表查询+切换+代理传值+打开视图
- Xcode删除所有的描述文件
- iOS沙盒路径会变化
- IOS传值的几种方式