ios - Objective-c 访问 plist 中的值
问题描述
我正在修改其他人的代码并努力访问 plist 中的值,我可以使用以下代码访问 Info.plist 等:
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Info.plist"];
NSDictionary *plistData = [NSDictionary dictionaryWithContentsOfFile:finalPath];
NSLog(@"ret=%@", plistData);
但是,当尝试访问 Account.plist 时,它返回 null,我假设这是路径问题?
任何帮助/指针表示赞赏。
解决方案
以下是如何从 plist 中获取 Dictionary 或 Array 的示例。
//*******************************************
- (NSArray *)loadArrayFromPlist:(NSString *)plistName {
NSString *plistPath = [[NSBundle mainBundle] pathForResource: plistName ofType: @"plist"];
return [NSArray arrayWithContentsOfFile: plistPath];
}
//*******************************************
- (NSDictionary *)loadDictionaryFromPlist:(NSString *)plistName {
NSString *plistPath = [[NSBundle mainBundle] pathForResource: plistName ofType: @"plist"];
return [NSDictionary dictionaryWithContentsOfFile: plistPath];
}
推荐阅读
- flutter - 如何在颤动中重塑多边形
- python - 使用 Python 和 Keras 库创建 LSTM 结构
- javascript - 我的 compile.js 文件中有一个关于 Solidity 项目的问题
- angular - 使用 Angular 11 反应形式与 forloop 进行样式绑定
- vb.net - WebBrowser - 此页面上的脚本出现错误
- javascript - 无法从 Mapbox 获取珠穆朗玛峰 RGB 平铺数据(未找到)
- javascript - 在 JS 函数式编程中执行多个实例方法的等价物是什么?
- azure-data-factory - Databricks 链接服务 Azure 数据工厂中的作业集群仅上传一个初始化脚本
- html - 您可以使用导航标签创建下拉菜单吗
- reactjs - 不能从 React 中的 useGlobalContext() 解构