我正在阅读example有多个配置并在运行时使用此Objective C代码访问活动配置:
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"Configuration" ofType:@"plist"];
NSDictionary *config = [NSDictionary dictionaryWithContentsOfFile:path];
获取活动配置值的Swift等效于@"Configuration"
是什么?
这不起作用:
var myDict: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource(@"Configuration", ofType: "plist") {
myDict = NSDictionary(contentsOfFile: path)
}
答案 0 :(得分:0)
只需删除@
,即可使用:
var myDict: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource("Configuration", ofType: "plist") {
myDict = NSDictionary(contentsOfFile: path)
}