简体   繁体   English

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

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

I have two NSMutableArrays(arrayContainsGoodClicks and arrayContainsBadClicks).我有两个 NSMutableArrays(arrayContainsGoodClicks 和 arrayContainsBadClicks)。 I am initializing these Arrays with some NSTimeInterval values when the relevant Good and Bad buttons are clciked.当点击相关的 Good 和 Bad 按钮时,我正在用一些 NSTimeInterval 值初始化这些 Arrays。 Now my requirement is, i am getting responses from a webservice call with some TimeIntervals.现在我的要求是,我从具有一些 TimeIntervals 的 Web 服务调用中获得响应。 Now, i want compare the NSTimeInterval values that i am getting from the Webservice responses with the values that i have stored in the two arrays. Please find below the code.现在,我想比较我从 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"

I am getting the response in the above mentioned format.我收到上述格式的回复。 I am parsing my file and storing the relevant details of NSTimeInterval Values.我正在解析我的文件并存储 NSTimeInterval 值的相关详细信息。 Now i want to compare the timeIntervals between 71 and 73 seconds(74 and 77,78 and 83 respectively).现在我想比较 71 和 73 秒之间的时间间隔(分别为 74 和 77,78 和 83)。 I have my arrays which contains all the timeInterval values at which the user has clicked the Good and Bad buttons.我有我的 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);}

My arrays contains the following sample details...我的 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"

) )

Can someone please help me on how to compare the NSTimeIntervals in my arrays and the received responses?有人可以帮我比较 arrays 中的 NSTimeIntervals 和收到的回复吗?

Seems quite trivial if you have the data in the correct format.如果您拥有正确格式的数据,这似乎是微不足道的。 NSTimeInterval is a typedef double so you can do comparisons using basic operators 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