从Info plist获取数据 [英] Getting data from the Info plist

查看:109
本文介绍了从Info plist获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我想从plist文件中获取数据时,我使用以下代码:

Whenever I want to get data from a plist file I use the following code:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"FILE_NAME" ofType:@"plist"];
NSDictionary *plistData = [NSDictionary dictionaryWithContentsOfFile:filePath]; 

但是现在我正在尝试从Info plist中读取数据,而filePath是nil。是否有不同的方法从Info plist中获取数据?

But now I'm trying to read in data from the Info plist, and filePath is nil. Is there a different way to get data from the Info plist?

推荐答案

从之前的SO 我的回答。您可以通过以下方式直接访问项目的info.plist中的属性...

From an earlier SO answer of mine. Attributes from the info.plist for your project are directly accessible by the following...

[[NSBundle mainBundle] objectForInfoDictionaryKey:key_name];

你的filePath只是因为无法找到文件而无法检查拼写&检查您尝试读取的文件是否实际位于捆绑包中等。

Your filePath is nil simply because it can't find the file - check spellings & check if the file you are trying to read from is actually in the bundle etc.

这篇关于从Info plist获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆