• <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 逛奔的蝸牛 閱讀(427) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
            麻豆精品久久精品色综合| 久久久久亚洲?V成人无码| 久久久久99精品成人片三人毛片| 久久www免费人成精品香蕉| 久久这里有精品视频| A级毛片无码久久精品免费| 久久国产免费观看精品3| 久久综合九色综合97_久久久| 久久久久久久亚洲精品| 久久精品青青草原伊人| 国产精品xxxx国产喷水亚洲国产精品无码久久一区| 久久线看观看精品香蕉国产| 女人高潮久久久叫人喷水| 色婷婷综合久久久中文字幕| 精品无码人妻久久久久久| 婷婷国产天堂久久综合五月| 国内精品久久久久伊人av| 四虎影视久久久免费| 久久久国产精品福利免费| 亚洲中文字幕无码一久久区| 久久国产综合精品五月天| 少妇人妻88久久中文字幕| 久久午夜无码鲁丝片午夜精品| 久久综合九色综合网站| 偷窥少妇久久久久久久久| 97精品国产97久久久久久免费| 久久精品www人人爽人人| 一级a性色生活片久久无| 国产精品99久久久久久www| 久久久久久久亚洲Av无码| 久久91精品国产91| 久久综合色老色| 亚洲精品97久久中文字幕无码| 国产一区二区三精品久久久无广告| 精品乱码久久久久久久| 亚洲精品白浆高清久久久久久| 中文字幕精品久久久久人妻| 一级做a爰片久久毛片看看| 香蕉久久永久视频| 婷婷国产天堂久久综合五月| 久久亚洲sm情趣捆绑调教|