In an Objective-C class, I want to load just once the contents of a text file into an NSString so that it can be used by all instances of that class.
In the Java world, I learnt over the years that it is easy to get this subtly wrong in terms of thread safety if you don't use a proven idiom. So I'd like to make sure I use the correct idiom.
Can you show me an example of an Objective-C class that does this?
Here's my empty class that I'm starting with...
@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