我正在查看以下苹果示例源代码:
/*
Cache the formatter. Normally you would use one of the date formatter styles (such as NSDateFormatterShortStyle), but here we want a specific format that excludes seconds.
*/
static NSDateFormatter *dateFormatter = nil;
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"h:mm a"];
}
试图弄明白:
为什么要使用static关键字?
如果每次调用该方法时都将其设置为nil,则这相当于缓存的变量.
该代码来自Tableview Suite demo中的示例4