如何比较NSMutableArray中的NSTimeInterval(NSNumber对象)?

时间:2012-04-09 15:52:52

标签: iphone objective-c ios5 nsmutablearray nstimeinterval

我有两个NSMutableArrays(arrayContainsGoodClicks和arrayContainsBadClicks)。我正在使用一些NSTimeInterval值初始化这些数组,当相关的Good和Bad按钮被clciked时。现在我的要求是,我收到来自带有一些TimeIntervals的webservice调用的响应。现在,我想比较我从Webservice响应获得的NSTimeInterval值与我存储在两个数组中的值。请在下面找到代码。

question answer="t" qno="1" tin="71" title="Greet" tout="73"
question answer="t" qno="2" tin="74" title="Have Name Tag" tout="77
question answer="t" qno="3" tin="78" title="Greet" tout="83"

我收到上述格式的回复。我正在解析我的文件并存储NSTimeInterval值的相关细节。现在我想比较71到73秒之间的timeIntervals(分别为74和77,78和83)。我的数组包含用户单击“好”和“坏”按钮的所有timeInterval值。

    -(void)onClickOfGood{
//NSLog(@"The current playback time in good:%g",moviePlayerController.currentPlaybackTime);
currentPlaybackTime = moviePlayerController.currentPlaybackTime;
NSNumber *goodTimeIntervals = [NSNumber numberWithDouble:currentPlaybackTime];
[arrayContainsGoodClicks addObject:goodTimeIntervals];
NSLog(@"The total count of Array is: %i",[arrayContainsGoodClicks count]);
NSLog(@"The Array contains : %@",arrayContainsGoodClicks);}

-(void)onClickOfBad{
NSLog(@"The current playback time in bad: %g",moviePlayerController.currentPlaybackTime);
currentPlaybackTime = moviePlayerController.currentPlaybackTime;
NSNumber *goodTimeIntervals = [NSNumber numberWithDouble:currentPlaybackTime];
[arrayContainsBadClicks addObject:goodTimeIntervals];
NSLog(@"The total count of Array is: %i",[arrayContainsBadClicks count]);
NSLog(@"The Array contains Bad Clicks are: %@",arrayContainsBadClicks);}

我的数组包含以下示例详细信息......

The Array containing Good Clicks are : (
"2.065027933",
"3.153256308",
"4.216946226",
"4.94465584",
"5.688772132",
"6.48904879",
"7.256447126",
"8.000711516000001",
"8.760312588",
"9.537493762",
"10.45637486",
"11.153212146",
"11.880587144",
"12.672884372",
"13.52852395"

The Array containing Bad Clicks are: (
"2.70485684",
"3.713548251",
"4.593316639",
"5.353822771",
"6.049754725",
"6.930190204",
"7.592959653",
"8.353438538000001",
"9.074305708000001",
"9.905327347",
"10.809726701",
"11.448938757",
"12.321753456",
"14.106061449"

有人可以帮助我如何比较我的阵列中的NSTimeIntervals和收到的回复吗?

1 个答案:

答案 0 :(得分:3)

如果您的数据格式正确,那么看起来非常简单。 NSTimeInterval是typedef double,因此您可以使用基本运算符进行比较

for(NSNumber* click in arrayContainsGoodClicks) {
    NSTimeInterval clickTimeInterval = [click doubleValue];     
    if(clickTimeInterval > 71.0 && clickTimeInterval < 73.0 ) {
       ...
    }
}