我有这个方法:
- (void) receivedData {
}
这应该每50到100毫秒运行一次。有没有办法检查自上次调用以来的时间并将最后一次打印到NSString?
答案 0 :(得分:1)
@interface MyClass() {
NSDate* receivedDataTimestamp;
....
}
...
-(void)receivedData {
NSDate* now = [NSDate date];
if (receivedDataTimestamp != nil) {
NSTimeInterval delta = [now timeIntervalSinceDate:receivedDataTimestamp];
NSLog(@"%f seconds since recevedData was called last", delta);
}
receivedDataTimestamp = now;
....
}