代码库> 其他> NSMutableArray NSArray 包含字典 排序 大全
NSMutableArray NSArray 包含字典 排序 大全
关注
上传者:yunhuaikong 分类:其他(Others)
查看次数:5899 下载次数:232
上传时间:2013-03-28 大小:7 B
SDK自有有比较,都是针对字符进行排序比较,如果我们从服务器获得很字典数据将其保存到一个数组中,需要对其按照价格,距离等进行排序时,无法再采用系统自有的方法进行排序,故,个人对其进行了扩展,以支持int float类型的比较排序。经过测试已经完全正确。




//比较的键,调用前必须设置
@property(nonatomic,retain) NSString*compareKey;


//整形,浮点型从小到大
- (NSComparisonResult)compareAscend:(NSMutableDictionary*)dic;


//整形,浮点型从大到小
- (NSComparisonResult)compareDescend:(NSMutableDictionary*)dic;


//其它比较,常用于字符串比较
- (NSComparisonResult)compareChar:(NSMutableDictionary*)dic;



使用方法:

for(NSMutableDictionary*dictionary inclubArray)
{
  [dictionary setCompareKey:@"Price"];
}
[clubArray sortUsingSelector:@selector(compareDescend:)];





以下为根据价格进行降序排列!
Printing description of clubArray:
<__NSArrayM 0x9455eb0>(
{
    Distance = "20.68";
    HotPoints = 93;
    IsOnline = True;
    Latitude = "22.721100";
    LogoURL = "201211/clubp_jtwdse.png";
    Longitude = "114.079500";
    Price = "2999.00";
    Province = 440000;
    SimpleIntroduction = "";
},
{
    Distance = "1232.79";
    HotPoints = 162;
    IsOnline = False;
    Latitude = "31.235040";
    LogoURL = "201208/20120822161157L.jpg";
    Longitude = "121.750400";
    Price = "1330.00";
    Province = 310000;
{
    Distance = "20.68";
    HotPoints = 451;
    IsOnline = False;
    Latitude = "22.721100";
    LogoURL = "201301/20130104122527L.jpg";
    Longitude = "114.079500";
    Price = "1100.00";
    Province = 440000;
},
{
    Distance = "1220.85";
    HotPoints = 106;
    IsOnline = False;
    Latitude = "30.985810";
    LogoURL = "201208/20120822140539L.jpg";
    Longitude = "121.895890";
    Price = "680.00";
    Province = 310000;
},
{
    Distance = "902.63";
    HotPoints = 105;
    IsOnline = False;
    Latitude = "29.715230";
    LogoURL = "201208/20120822160751L.jpg";
    Longitude = "118.256110";
    Price = "670.00";
    Province = 340000;
},
{
    Distance = "261.56";
    HotPoints = 105;
    IsOnline = True;
    Latitude = "23.063540";
    LogoURL = "201208/20120822170853L.jpg";
    Longitude = "116.534430";
    Price = "530.00";
    Province = 440000;
},
{
    Distance = "56.94";
    HotPoints = 125;
    IsOnline = False;
    Latitude = "22.943535";
    LogoURL = "";
    Longitude = "114.387417";
    Price = "500.00";
    Province = 440000;
},
{
    Distance = "3677.31";
    HotPoints = 72;
    IsOnline = False;
    Latitude = "45.563343";
    LogoURL = "201208/20120823161310L.jpg";
    Longitude = "84.886036";
    Price = "180.00";
    Province = 650000;
}
)

收藏
我来说两句
发表评论
您还没有登录!请登录注册
所有评论(0
提示
sina weixin mail 回到顶部