iOS 开发实用技术导航
NSHipster 中文版
› http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
› http://www.cocos2d-iphone.org/
CocoaPods
› http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
› http://code.google.com/mobile/analytics/
WWDC
› https://developer.apple.com/wwdc/
Design Guides and Resources
› https://developer.apple.com/design/
Transcripts of WWDC sessions
› http://asciiwwdc.com
Cocoa with Love
› http://cocoawithlove.com/
Cocoa Dev Central
› http://cocoadevcentral.com/
NSHipster
› http://nshipster.com/
Style Guides
› Google Objective-C Style Guide
› NYTimes Objective-C Style Guide
Useful Tools and Services
› Charles Web Debugging Proxy
› Smore
Castalia
V2EX  ›  iDev

请教一个 NSArray 的排序的问题

  •  
  •   Castalia · Jan 29, 2012 · 5056 views
    This topic created in 5364 days ago, the information mentioned may be changed or developed.
    有一个由 NSDictionary 组成的 NSArray,现在希望这个 array 中元素按照 dictionary 的某个 NSNumber 属性的大小来排倒序,应该如何实现呢?
    2 replies  •  1970-01-01 08:00:00 +08:00
    linlinqi
        1
    linlinqi  
       Jan 29, 2012
    用sortedArrayUsingComparator是不是可以呢
    <pre>
    NSArray *sortedArray;
    sortedArray = [drinkDetails sortedArrayUsingComparator:^(id a, id b) {
    NSDate *first = [(Person*)a birthDate];
    NSDate *second = [(Person*)b birthDate];
    return [first compare:second];
    }];
    </pre>

    见
    http://stackoverflow.com/questions/805547/how-to-sort-an-nsmutablearray-with-custom-objects-in-it
    lizdo
        2
    lizdo  
       Jan 29, 2012
    楼上的改成NSNumber *first = [a objectForKey:xxx];就可以了
    这种问题的确StackOverflow比较无敌
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2380 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:15 · PVG 19:15 · LAX 04:15 · JFK 07:15
    ♥ Do have faith in what you're doing.