开发者

Timer invalidate

开发者 https://www.devze.com 2022-12-21 05:12 出处:网络
What is the meaning of this statement given? NSTim开发者_如何学JAVAer *timer ,[timer invalidate]

What is the meaning of this statement given?

NSTim开发者_如何学JAVAer *timer ,[timer invalidate]


It's an objective C timer statement that cancels a running timer.

Normally it would be expressed as:

NSTimer* myTimer = [NSTimer timerWithTimeInterval:1.0 target:self
                                             selector:@selector(calculateTLE) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:myTimer forMode: NSDefaultRunLoopMode];

..

[myTimer invalidate];


It looks as though you're creating an instance of NSTimer without defining it, and then in the same line for whatever reason stopping that same timer. Waste of memory allocation resources, unless you're planning to use the timer at a later time, in which case you should trigger the timer then.

0

精彩评论

暂无评论...
验证码 换一张
取 消