我正在阅读 example用于拥有多个配置并在运行时使用以下 Objective C 代码访问事件配置:
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"Configuration" ofType:@"plist"];
NSDictionary *config = [NSDictionary dictionaryWithContentsOfFile:path];
用于获取事件配置值的 @"Configuration"
的 Swift 等效项是什么?
这不起作用:
var myDict: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource(@"Configuration", ofType: "plist") {
myDict = NSDictionary(contentsOfFile: path)
}
最佳答案
只需删除@
,它就会起作用:
var myDict: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource("Configuration", ofType: "plist") {
myDict = NSDictionary(contentsOfFile: path)
}
关于Swift:当前配置的占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35906343/