我对排序 NsArray 感到困惑,因为它在 iOS 开发中是非常新的,我有一个自定义数组,我想对我的 NsArray 进行排序,它的值如下分组 bycallType
和numberId
:
{
callID = 1;
callType = 4;
dateTime = "2013-10-11 14:42:10 +0000";
durationOfCall = "00:00:27";
numberCalled = 91xxxxxxxxx;
numberId = 8;
},
{
callID = 1;
callType = 4;
dateTime = "2013-10-11 14:24:19 +0000";
durationOfCall = "00:00:15";
numberCalled = 91xxxxxxxxx;
numberId = 9;
},
{
callID = 1;
callType = 4;
dateTime = "2013-10-11 13:59:18 +0000";
durationOfCall = "00:00:11";
numberCalled = 91xxxxxxxxx;
numberId = 8;
},
{
callID = 1;
callType = 4;
dateTime = "2013-10-11 13:57:55 +0000";
durationOfCall = "00:00:09";
numberCalled = 91xxxxxxxxx;
numberId = 8;
},
{
callID = 1;
callType = 4;
dateTime = "2013-10-11 13:56:02 +0000";
durationOfCall = "00:00:12";
numberCalled = 91xxxxxxxxx;
numberId = 8;
},
{
callID = 1;
callType = 4;
dateTime = "2013-10-11 13:55:41 +0000";
durationOfCall = "00:00:00";
numberCalled = 91xxxxxxxxx;
numberId = 8;
}
)
结果应该是我在每组中得到计数的地方
{
count = 4 // number of
callID = 1;
callType = 4;
dateTime = "2013-10-11 14:42:10 +0000";
durationOfCall = "00:00:27";
numberCalled = 91xxxxxxxxx;
numberId = 8;
},
{
count = 1 // number of
callID = 1;
callType = 4;
dateTime = "2013-10-11 14:24:19 +0000";
durationOfCall = "00:00:27";
numberCalled = 91xxxxxxxxx;
numberId = 9;
}
}
这是我上面的自定义类
#import <Foundation/Foundation.h>
@interface RecentCallsModel : NSObject
@property (nonatomic, retain) NSNumber *callID; // Integer 32
@property (nonatomic, retain) NSNumber *callType; // Integer32
@property (nonatomic, retain) NSString *numberId; // Either phone number or the contact id
@property (nonatomic, retain) NSDate *dateTime; //Date and time
@property (nonatomic, retain) NSString *durationOfCall;
@property (nonatomic, retain) NSString *numberCalled;
@end