• <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://m.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
            posted on 2011-12-02 00:03 逛奔的蝸牛 閱讀(427) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
            久久热这里只有精品在线观看| 久久久久久A亚洲欧洲AV冫| 很黄很污的网站久久mimi色 | 亚洲欧美精品伊人久久| 人妻少妇精品久久| 久久99精品久久久久子伦| 精品久久久无码中文字幕天天| 狠狠色丁香久久婷婷综合图片| 久久99精品国产自在现线小黄鸭 | 亚洲AV日韩精品久久久久| 精品国产91久久久久久久a| 国产成人精品久久| 国产亚洲色婷婷久久99精品91| 久久久久亚洲av无码专区| 久久精品亚洲一区二区三区浴池 | 热久久这里只有精品| 亚洲精品第一综合99久久| 国产精品禁18久久久夂久| 久久人人爽人人爽人人爽 | 久久久精品人妻一区二区三区四| 久久精品中文字幕第23页| 久久99国产精品久久| 久久久婷婷五月亚洲97号色| 久久精品视频一| 日本亚洲色大成网站WWW久久| 国产韩国精品一区二区三区久久| 无码人妻久久一区二区三区 | 精品国产乱码久久久久久1区2区| 亚洲va中文字幕无码久久| 久久香蕉国产线看观看猫咪?v| 2021最新久久久视精品爱| 波多野结衣久久一区二区| 久久久久99精品成人片三人毛片| 国产福利电影一区二区三区久久久久成人精品综合 | 欧美伊香蕉久久综合类网站| 久久成人精品视频| 91精品国产高清久久久久久91 | 久久96国产精品久久久| 大香网伊人久久综合网2020| 伊人丁香狠狠色综合久久| 99久久99久久精品国产片|