字符串之间比较大小(可转化为对象)
来源:互联网 发布:数据可视化软件 ta 编辑:程序博客网 时间:2024/05/29 07:16
Student *stu1=[[Studentalloc] init];
stu1.name=@"xiaolongxia";
stu1.age=18;
Student *stu2=[Studentnew];
stu2.name=@"dazhaxie";
stu2.age=23;
NSMutableArray *mularr=[NSMutableArrayarrayWithObjects:stu1,stu2, nil];
//第一种比较
[mularrsortUsingSelector:@selector(compareWithName:)];
for (int i=0; i<mularr.count; i++) {
NSLog(@"%@",mularr[i]);
}
[mularrsortUsingSelector:@selector(compareWithAge:)];
for (int i=0; i<mularr.count; i++) {
NSLog(@"%@",mularr[i]);
}
//第二种
[mularrsortUsingComparator:^NSComparisonResult(Student *obj1,Student *obj2) {
return [obj1 compareWithName:obj2];
}];
for (id objin mularr) {
NSLog(@"%@",obj);
}
[mularrsortUsingComparator:^NSComparisonResult(Student *obj1,Student *obj2) {
int result;
if (obj1.age>obj2.age) {
result=NSOrderedDescending;
}elseif(obj1.age<obj2.age){
result=NSOrderedAscending;
}else {
result=NSOrderedSame;
}
return result;
}];
for (id objin mularr) {
NSLog(@"%@",obj);
}
//第三种
NSSortDescriptor *desc=[NSSortDescriptorsortDescriptorWithKey:@"name"ascending:YES];
[mularrsortUsingDescriptors:@[desc]];
NSEnumerator *e=[mularr objectEnumerator];
NSLog(@"%@",[eallObjects]);
NSSortDescriptor *desc1=[NSSortDescriptorsortDescriptorWithKey:@"age"ascending:YES];
[mularrsortUsingDescriptors:@[desc1]];
NSEnumerator *ee=[mularr objectEnumerator];
NSLog(@"%@",[eeallObjects]);
- 字符串之间比较大小(可转化为对象)
- JOSN对象转化为字符串,字符串转化为JSON对象
- 字符串、字节数组、可序列化对象之间的相互转化
- 将对象转化为字符串
- json字符串转化为对象
- 字符串之间的大小比较方法
- iOS对象(字典或数组)转化为JSon字符串
- iOS对象(字典或数组)转化为JSon字符串
- json字符串转化为java对象(一)
- 比较两个可为null的对象
- 把字符串转化为json对象
- 【common】JavaScript ----- 对象转化为json字符串
- js中字符串转化为jsion对象
- js把字符串转化为对象、数组
- java对象转化为json字符串
- 将json字符串转化为Map对象
- JSON字符串转化为JSONOBJECT对象
- Dom节点对象转化为字符串
- Core Animation 3D介绍(第2部分)
- jmeter 监听器
- Apache启用mod_deflate的gzip压缩
- Shell之定时拉起脚本
- 怎么用clementine做关联规则分析
- 字符串之间比较大小(可转化为对象)
- Android应用加入微信分享
- 去掉字符里的html标签
- maven导出项目依赖的jar包
- jsp页面防止刷新重复提交解决方案
- 常用js特效之左上角菜单
- 页面设计
- 用php调用接口api
- 关于scrollview嵌套listview的方法。但官方并不推荐这种做法。