Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含 RGB 值的数组,我将其定义为:
static const RGB rgbValues[] = { { 255, 0, 0 }, { 223, 123, 213 }, { 255, 10, 23 }, { 255, 230, 100 }, };
但是我想从 plist 加载值。我知道如何从 plist 中读取并提取值,但是我自然不能将该代码放入静态 const 数组声明中。
有人可以建议我在哪里/如何做吗?
谢谢你。
不知道你的 plist 的格式很难提供一个准确的答案,无论如何你想使用NSArray它的initWithContentsOfFile:初始化器。就像是
NSArray
initWithContentsOfFile:
NSString * filePath = [[NSBundle mainBundle] pathForResource:@"rgb" ofType:@"plist"]; NSArray * rgbArray = [[NSArray alloc] initWithContentsOfFile:filePath];