gpt4 book ai didi

iphone - 在字符串文件中存储键/值对

转载 作者:行者123 更新时间:2023-11-29 11:15:09 27 4
gpt4 key购买 nike

目前我存储字符串的方式是使用 Localizable.strings,例如

英语:

"URL" = "http://google.com";

西类牙语:

"URL" = "http://google.com";

如您所见,我对两种语言都有相同的字符串,有没有一种方法可以使用类似于 localizable.strings 的东西(自动加载,与任何语言/本地化兼容),而不必在其中写入相同的键/值两个文件?然后使用方法检索值? ( NSGetstring("URL") )

最佳答案

或许您可以将键/值对存储在一个 plist 中并将其读入您的代码中。像这样:

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"myList.plist"];
plistDictionary = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];

只需将您的信息存储在 plist 中,然后像访问任何其他字典项一样访问它:

NSLog(@"URL: %@", [plistDictionary objectForKey:@"URL"]);

关于iphone - 在字符串文件中存储键/值对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9796274/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com