无法在Swift 2框架中访问info.plist

RealSmoo

无论我做什么,似乎都无法访问框架文件夹根目录中的Info.plist文件。到目前为止,我的代码如下所示:

    private var Config: NSDictionary {
    get {
        if let config = NSBundle.mainBundle().pathForResource("Info", ofType: "plist") {
            return NSDictionary(contentsOfFile: config)!
        }
        return Dictionary<String, AnyObject>()
    }
}

这将返回null Dictionary,因为该if let config语句未通过。我也尝试过:

    private var Config: NSDictionary {
    get {
        if let config = NSBundle.mainBundle().infoDictionary {
            return NSDictionary(contentsOfFile: config as! String)!
        }
        return Dictionary<String, AnyObject>()
    }
}

这次,该if let语句通过了,但是为空Dictionary(0个键/值对)。

我正在使用Xcode 7.2.1。帮助iOS新手!提前致谢。:)

RealSmoo

解决了!

在进行了更多研究之后,我发现对于框架而言,访问访问者或与此相关的一般资源是不同的。因此,我尝试:

            if let config = NSBundle(identifier: "Smoo.Framework")?.infoDictionary {
            return NSDictionary(dictionary: config["Key"] as! NSDictionary)
        }

(“ Smoo.Framework”是我所需的plist所在的包的名称)

那行得通!案件结案。:)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章