plist文件相关

1、读取plist文件中的Boolean类型的字段值时,要先把它转为NSNumber类型,然后通过NSNumber的boolValue方法来读取该值。

读取:

   

   jewel=[[dic objectForKey:@"jewel"]intValue];

   globalData .isChineseLanguage =[[setting objectForKey : @"isChineseLanguage" ] boolValue ];


写入:

   [dic setObject:[NSNumber numberWithInt:jewel] forKey:@"jewel"];

   [setting setObject:[[NSNumber alloc]initWithBool:globalData.isChineseLanguage]forKey:@"isChineseLanguage"];

   

2读取部分

-(NSString *)getSettingpath{

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory=[paths objectAtIndex:0];

    NSString *path=[documentsDirectory stringByAppendingPathComponent:@"Setting.plist"];

    

    //本地还没写入时,从配置中读取

    if(![[NSFileManager defaultManager] fileExistsAtPath:path]) {

        NSString *newpath = [[NSBundle mainBundle] pathForResource:@"Setting" ofType:@"plist"];

        CCLOG(@"setting的初始路径%@",newpath);

        setting=[[NSMutableDictionary alloc] initWithContentsOfFile:newpath];

        [setting writeToFile:path atomically:YES];

    }

    return path;

}



已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页