• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::
            Question: What I want to do seems pretty simple, but I can't find any answers on the web. I have an NSMutableArray of objects, let's say they are 'Person' objects. I want to sort the NSMutable array by Person.birthDate which is an NSDate.

            1. Either you implement a compare-method for your object:

            - (NSComparisonResult)compare:(Person *)otherObject {
               
            return [self.birthDate compare:otherObject.birthDate];
            }

            NSArray *sortedArray = [drinkDetails sortedArrayUsingSelector:@selector(compare:)];


            2. or usually even better: (The default sorting selector of NSSortDescriptor is compare:)

            NSSortDescriptor *sortDescriptor;
            sortDescriptor
            = [[[NSSortDescriptor alloc] initWithKey:@"birthDate"
                                                          ascending
            :YES] autorelease];
            NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
            NSArray *sortedArray;
            sortedArray
            = [drinkDetails sortedArrayUsingDescriptors:sortDescriptors];

            3. See the NSMutableArray method sortUsingFunction:context:
            NSComparisonResult compare(Person *firstPerson, Person *secondPerson, void *context) {
             
            if ([firstPerson birthDate] < [secondPerson birthDate])
               
            return NSOrderedAscending;
             
            else if ([firstPerson birthDate] > [secondPerson birthDate])
               
            return NSOrderedDescending;
             
            else
               
            return NSOrderedSame;
            }
            int SortPlays(id a,  id b, void* context) {
               
            Play* p1=a;
               
            Play* p2=b;
               
            if (p1.score<p2.score) return NSOrderedDescending;
               
            else if (p1.score>p2.score) return NSOrderedAscending;
               
            return NSOrderedSame;
            }

            ...
            [validPlays sortUsingFunction:SortPlays context:nil];

            4. Starting in iOS 4 you can also use blocks for sorting.
            NSArray *arrayToSort = where ever you get the array from... ;
            NSComparisonResult (^sortBlock)(id, id) = ^(id obj1, id obj2) {
             
            if ([obj1 position] > [obj2 position]) {
               
            return (NSComparisonResult)NSOrderedDescending;
             
            }
             
            if ([obj1 position] < [obj2 position]) {
               
            return (NSComparisonResult)NSOrderedAscending;
             
            }
             
            return (NSComparisonResult)NSOrderedSame;
            };
            NSArray *sorted = [arrayToSort sortedArrayUsingComparator:sortBlock];
            featuresArray = [unsortedFeaturesArray sortedArrayUsingComparator: ^(id a, id b){ ... }]
            @import url(http://www.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
            posted on 2011-12-02 00:03 逛奔的蝸牛 閱讀(422) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
            亚洲日本久久久午夜精品| 亚洲国产成人久久综合碰| 少妇被又大又粗又爽毛片久久黑人| 久久天堂AV综合合色蜜桃网 | 激情伊人五月天久久综合| 久久精品国产亚洲AV香蕉| 亚洲午夜精品久久久久久app| 国产免费久久精品丫丫| 99久久亚洲综合精品成人| 精品国产福利久久久| 狠狠色丁香婷综合久久| 久久综合久久综合久久| 色综合久久久久| 久久精品三级视频| 久久久久国色AV免费观看| 久久久久免费视频| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 久久人人爽人人人人爽AV| 久久精品极品盛宴观看| 久久精品国产乱子伦| 无码人妻少妇久久中文字幕蜜桃| 亚洲乱码精品久久久久..| 久久夜色精品国产欧美乱| 久久精品国产亚洲av高清漫画 | 一本大道久久a久久精品综合| 99久久国产综合精品五月天喷水 | 久久国产精品无码一区二区三区| 亚洲精品高清国产一线久久| 久久综合给久久狠狠97色| 久久精品成人免费网站| 久久久久国色AV免费观看| 青青草原综合久久大伊人| 久久九九精品99国产精品| 女人香蕉久久**毛片精品| 日韩欧美亚洲综合久久影院Ds | 久久久久久无码Av成人影院| 狠狠色丁香婷婷综合久久来| 久久综合狠狠综合久久97色| 亚洲va久久久噜噜噜久久| 99久久国产综合精品五月天喷水 | 色综合久久88色综合天天|