【发布时间】:2014-01-24 03:29:22
【问题描述】:
我在一个 Constants.m 文件中声明了一些静态数组,例如我的 tableView 的 numberOfRowsInSection 计数:
+ (NSArray *)configSectionCount
{
static NSArray *_configSectionCount = nil;
@synchronized(_configSectionCount) {
if(_configSectionCount == nil) {
_configSectionCount = [NSArray arrayWithObjects:[NSNumber numberWithInt:2], [NSNumber numberWithInt:2], [NSNumber numberWithInt:4], [NSNumber numberWithInt:3], [NSNumber numberWithInt:0], nil];
}
return _configSectionCount;
}
}
这是最好的方法吗?是否有必要像这样声明它们?
【问题讨论】:
-
查看
dispatch_once而不是@synchronized。
标签: objective-c static constants