NStime计时器
#import "计时器.h"
@interface ___ ()
@property(
weak,
nonatomic)NSTimer*time;
@end
@implementation ___
-(
void)time{
self.time=[NSTimer scheduledTimerWithTimeInterval:
1 target:
self selector:
@selector(timerFired) userInfo:
nil repeats:
YES];
}
-(
void)timerFired{
static int hour=
0;
static int minute=
0;
static int second=
0;
second+=
1;
if (second==
60) {
minute+=
1;
second=
0;
if (minute==
60) {
hour+=
1;
minute=
0;
if (hour==
24) {
hour=
0;
}
}
}
}
-(
void)dealloc{
[
self.time invalidate];
}
@end
注:使用NStime时应注意内存释放问题,防止内存泄漏
转载请注明原文地址: https://ju.6miu.com/read-667103.html