In the Objective-C class, I want to load only the contents of a text file into NSString once so that it can be used by all instances of this class.
In the Java world, I have learned over the years that it is easy to get this inaccurate error in terms of thread safety if you are not using a proven idiom. Therefore, I would like to make sure that I am using the correct idiom.
Can you show me an example of an Objective-C class that does this?
Here is my empty class 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
source share