문제

Some thing like this:

@property (nonatomic,assign) NSTimeInterval *startTime;

AVAudioPlayer *player;

And I want to do this

if (self.player.currentTime  > sub.startTime) {
    do something...
}

I think they are both NSTimeInterval type data, why I can't do this?

If I change the up code like this

if (self.player.currentTime  > 5) {
    do something...
}

It can works very well.

도움이 되었습니까?

해결책

NSTimeInterval is just a typedef of double. It's not an Objective-C object, so you should probably not use a pointer as your property. You should just use a plain NSTimeInterval:

@property (nonatomic) NSTimeInterval startTime;

다른 팁

NSTimeInterval is declared like this

typedef double NSTimeInterval;

You can implement some helper method like this

static double NSTimeIntervalEqualCompareThreshold = 0.01;

NSComparisonResult NSTimeIntervalCompare(NSTimeInterval time1, NSTimeInterval time2)
{
    if (abs(time2 - time1) < NSTimeIntervalEqualCompareThreshold) {
        return NSOrderedSame;
    } else if (time1 < time2) {
        return NSOrderedAscending;
    } else {
        return NSOrderedDescending;
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top