繁体   English   中英

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

[英]How to compare the NSTimeInterval(NSNumber Objects) inside a NSMutableArray?

我有两个 NSMutableArrays(arrayContainsGoodClicks 和 arrayContainsBadClicks)。 当点击相关的 Good 和 Bad 按钮时,我正在用一些 NSTimeInterval 值初始化这些 Arrays。 现在我的要求是,我从具有一些 TimeIntervals 的 Web 服务调用中获得响应。 现在,我想比较我从 Web 服务响应中获得的 NSTimeInterval 值与我存储在两个 arrays 中的值。请在代码下方找到。

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 秒之间的时间间隔(分别为 74 和 77,78 和 83)。 我有我的 arrays,其中包含用户单击 Good 和 Bad 按钮时的所有 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);}

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

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"

)

有人可以帮我比较 arrays 中的 NSTimeIntervals 和收到的回复吗?

如果您拥有正确格式的数据,这似乎是微不足道的。 NSTimeInterval 是一个typedef double ,因此您可以使用基本运算符进行比较

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM