【发布时间】:2009-02-16 23:10:59
【问题描述】:
我正在查看以下苹果示例源代码:
/*
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
【问题讨论】:
标签: objective-c caching static