想要比较CMTime并基于我正在执行的循环。转换ObjectiveC为Swift,我找不到合适的方法CMTIME_COMPARE_INLINE。
CMTime oneSecond = CMTimeMake( 1, 1 );
CMTime oneSecondAgo = CMTimeSubtract( timestamp, oneSecond );
while( CMTIME_COMPARE_INLINE( [_previousSecondTimestamps[0] CMTimeValue], <, oneSecondAgo ) ) {
[_previousSecondTimestamps removeObjectAtIndex:0];
}
Run Code Online (Sandbox Code Playgroud)
有人在任何版本中遇到过类似的问题吗Swift?
CMTime在 Swift 3 中作为Comparable类型导入,因此,您无需使用CMTIME_COMPARE_INLINE.
假设_previousSecondTimestamps类型为[CMTime](*1),您可以在 Swift 3 中编写如下内容:
let oneSecond = CMTime(seconds: 1.0, preferredTimescale: 1)
let oneSecondAgo = timestamp - oneSecond
while !_previousSecondTimestamps.isEmpty && _previousSecondTimestamps[0] < oneSecondAgo {
_previousSecondTimestamps.remove(at: 0)
}
Run Code Online (Sandbox Code Playgroud)
*1 在 Swift 中,你可以直接声明一个 Array CMTime,不需要使用NSMutableArraycontains NSValue。