zoukankan      html  css  js  c++  java
  • iOS 对时间排序

    ios 对时间排序

     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"]);

        }

     

  • 相关阅读:
    UI自动化测试模型
    Selenium:HTML测试报告
    Selenium:浏览器及鼠标、键盘事件
    Selenium:WebDriver简介及元素定位
    selenium自动化环境搭建(Windows)
    浅谈UI自动化测试
    《MySQL:菜鸟入门系列》
    《HTTP协议:菜鸟入门系列》
    人人都是产品经理<1.0>
    聊聊连接池和线程
  • 原文地址:https://www.cnblogs.com/song-kl/p/4744122.html
Copyright © 2011-2022 走看看