iOS:为什么我不能一起添加两个NSTimeIntervals?

Bea*_*ore 0 objective-c nstimer nstimeinterval

根据这篇文章, 我应该能够简单地+ =两个NSTimeIntervals ...但我不能.我试图处理秒表上的"暂停"并能够继续使用"运行计数器",以便说出名为totalDuration的NSTimeInterval.但是当我做以下事情时

NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
// Add the saved interval
totalDuration += timeInterval;
Run Code Online (Sandbox Code Playgroud)

我明白了:

.../Views/bdNewTrackViewController.m:506:19: Invalid operands to binary expression ('NSTimeInterval *' (aka 'double *') and 'NSTimeInterval' (aka 'double'))

百思不得其解......

Ita*_*ber 6

您的totalDuration变量未声明为NSTimeInterval; 它被声明为指向NSTimeInterval(NSTimeInterval *)的指针.在声明中删除星号,totalDuration你应该是好的.