字典--plist

mac2022-06-30  21

利用 plist 把字典的数组放到plist文件中,以后就可以不改代码,需要增删数据就直接修改plist文件 - (NSArray*)imageData {     if (_imageData == nil) { // 从未初始化         // 初始化数据         NSMutableDictionary *image1 = [NSMutableDictionary dictionary];         image1[MJIconKey] = @"biaoqingdi";         image1[MJDescKey] = @"在他面前,其他神马表情都弱爆了!";                 NSMutableDictionary *image2 = [NSMutableDictionary dictionary];         image2[MJIconKey] = @"wangba";         image2[MJDescKey] = @"哥们为什么选八号呢";                 NSMutableDictionary *image3 = [NSMutableDictionary dictionary];         image3[MJIconKey] = @"bingli";         image3[MJDescKey] = @"这也忒狠了";                 NSMutableDictionary *image4 = [NSMutableDictionary dictionary];         image4[MJIconKey] = @"chiniupa";         image4[MJDescKey] = @"chiniupa";                 NSMutableDictionary *image5 = [NSMutableDictionary dictionary];         image5[MJIconKey] = @"danteng";         image5[MJDescKey] = @"亲,你能改下你的网名么?哈哈";         //        NSMutableDictionary *image6 = [NSMutableDictionary dictionary]; //        image6[MJIconKey] = @"chiniupa"; //        image6[MJDescKey] = @"新增的数据哈哈哈哈哈哈";                 _imageData = @[image1, image2, image3, image4, image5];     }     return _imageData; }   plist文件的调用 - (NSArray*)imageData {     if (_imageData == nil) { // 从未初始化         // 初始化数据         // File : 全路径         // NSBundle : 一个NSBundle代表一个文件夹 1.NSBundle 1> 一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹 2> 利用mainBundle就可以访问软件资源包中的任何资源 3> 模拟器应用程序的安装路径 /Users/aplle/资源库/Application Support/iPhone Simulator/7.1/Applications           // 利用mainBundle就可以访问软件资源包中的任何资源         NSBundle *bundle = [NSBundle mainBundle];                 //  获得imageData.plist的全路径         NSString *path = [bundle pathForResource:@"imageData" ofType:@"plist"];                 _imageData = [NSArray arrayWithContentsOfFile:path];     }     return _imageData; }

转载于:https://www.cnblogs.com/ljwiOS/p/5218899.html

最新回复(0)