【发布时间】:2012-08-28 13:26:05
【问题描述】:
在 Objective-C 类中,我只想将文本文件的内容加载到 NSString 中,以便该类的所有实例都可以使用它。
多年来,我在 Java 世界中了解到,如果不使用经过验证的惯用语,就线程安全而言很容易犯这种微妙的错误。所以我想确保我使用正确的成语。
你能告诉我一个Objective-C类的例子吗?
这是我开始的空课......
@interface TestClass : NSObject
- (NSString *)doSomething:(NSUInteger)aParam;
@end
@implementation TestClass {
}
- (id)init {
self = [super init];
if (self) {
}
return self;
}
- (NSString *)doSomething:(NSUInteger)aParam {
// something with shared NSString loaded from text file,
// depending on the value of aParam
return @"";
}
@end
【问题讨论】:
标签: objective-c idioms