.h文件中
@property (strong, nonatomic) NSDictionary *dic;
+ (id)getResourceManager;
- (NSString *)getByKey:(NSString *)key;
.m文件中
static ResourceManager *resourceManager = nil;
+(id)getResourceManager{
@synchronized (self){
if (resourceManager == nil) {
resourceManager = [[ResourceManager alloc]init];
}
}
return resourceManager;
}
- (id)init{
if (self = [super init]) {
NSString *str = [[NSBundle mainBundle]pathForResource:@"angua" ofType:@"plist"];
_dic = [[NSDictionary alloc]initWithContentsOfFile:str];
}
return self;
}
- (NSString *)getByKey:(NSString *)key
{
return [_dic objectForKey:key];
}
在其他类中使用,从plist文件中获取信息:
ResourceManager *resourceManager;
resourceManager = [ResourceManager getResourceManager];
asd.text = [resourceManager getByKey:@"asdfg"]; //文本上显示“中国人”
或者[[ResourceManager getResourceManager]getByKey:@"asdfg"]; //文本上显示“中国人”