对时间进行排序-创新互联
//排序 对时间进行排序
NSMutableArray *dataArray=[[NSMutableArray alloc]initWithCapacity:0];
NSMutableDictionary *dir=[[NSMutableDictionary alloc]init];
[dir setObject:@"2012-12-02" forKey:@"time"];
[dataArray addObject:dir];
[dir release];
NSMutableDictionary *dir1=[[NSMutableDictionary alloc]init];
[dir1 setObject:@"2012-02-15" forKey:@"time"];
[dataArray addObject:dir1];
[dir1 release];
NSMutableDictionary *dir2=[[NSMutableDictionary alloc]init];
[dir2 setObject:@"2012-03-02" forKey:@"time"];
[dataArray addObject:dir2];
[dir2 release];
NSMutableDictionary *dir3=[[NSMutableDictionary alloc]init];
[dir3 setObject:@"2000-03-02" forKey:@"time"];
[dataArray addObject:dir3];
[dir3 release];
NSMutableDictionary *dir4=[[NSMutableDictionary alloc]init];
[dir4 setObject:@"2112-03-02" forKey:@"time"];
[dataArray addObject:dir4];
[dir4 release];
NSMutableArray *myArray=[[NSMutableArray alloc]initWithCapacity:0];
[myArray addObjectsFromArray:dataArray];
//[myArray release];
[dataArray release];
for (int i=0; i<[myArray count]; i++) {
NSLog(@"排序前----->>%@",[[myArray objectAtIndex:i] objectForKey:@"time"]);
}
NSSortDescriptor*sorter=[[NSSortDescriptor alloc]initWithKey:@"time" ascending:YES];
NSMutableArray *sortDescriptors=[[NSMutableArray alloc]initWithObjects:&sorter count:1];
NSArray *sortArray=[myArray sortedArrayUsingDescriptors:sortDescriptors];
[sorter release];
for (int i=0; i<[sortArray count]; i++) {
NSLog(@"排序后----->>%@",[[sortArray objectAtIndex:i] objectForKey:@"time"]);
}
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
分享标题:对时间进行排序-创新互联
新闻来源:http://cdiso.cn/article/cdigsi.html