按日期排序的对象,数组中的时间问题(Iphone开发) [英] Objects Sorting With date ,Time Problem in Array(Iphone Development)

查看:75
本文介绍了按日期排序的对象,数组中的时间问题(Iphone开发)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到与数组排序有关的问题。

I have Problem related to array Sorting.

我有一个NSMutable数组说是A.它在每个索引上都有一个类对象b。

I have an NSMutable array say's A.Which has an class object b on its each index.

class b包含多个字段,如int,string和nsdate。

class b contain's multiple field Like int,string and nsdate.

我想基于b类对A数组进行排序时间(NSdate)上升。

I want to sort the A array on the basis of class b time(NSdate) ascendingly.

我遵循stackoverflow上的日期排序问题,但这仅适用于日期数组。

I follow the date sorting question on stackoverflow but that's only for date array.

对NSArray的日期字符串或对象进行排序

请指导我。

提前感谢

推荐答案

怎么样:

NSArray *myArray = [NSArray arrayWithObjects:
                    [NSDictionary dictionaryWithObjectsAndKeys:[NSDate distantFuture], @"theDate", nil],
                    [NSDictionary dictionaryWithObjectsAndKeys:[NSDate distantPast], @"theDate", nil],
                    nil];
NSLog(@"Before sorting: %@", myArray);
NSSortDescriptor *dateSortDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"theDate" ascending: YES];

NSArray *sortedArray = [myArray sortedArrayUsingDescriptors:[NSArray arrayWithObject: dateSortDescriptor]];
NSLog(@"After Sorting: %@", sortedArray);

这假设您要排序的日期有一个密钥(它本质上是一个属性。 )

This presumes that the date you want to sort for has a key (it is a property, essentially.)

这篇关于按日期排序的对象,数组中的时间问题(Iphone开发)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆