在 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