请问下面static int n = 0; 这里的static有什么作用
- (void)timerAction:(NSTimer *)timer {
static int n = 0;
NSFileHandle *fileHandle = timer.userInfo;
//跳到文件的末尾
[fileHandle seekToEndOfFile];
NSDate *nowDate = [NSDate date];
NSDateFormatter *dateformate = [[NSDateFormatter alloc] init];
//设置日期的格式
[dateformate setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
//将日期对象格式为字符串
NSString *datestring = [dateformate stringFromDate:nowDate];
[dateformate release];
datestring = [datestring stringByAppendingString:@"\n"];
NSData *data = [datestring dataUsingEncoding:NSUTF8StringEncoding];
[fileHandle writeData:data];
if (n == 10) {
[timer invalidate];
//关闭文件
[fileHandle closeFile];
}
n++;
}
|