<bdo id='M3TfG'></bdo><ul id='M3TfG'></ul>

<small id='M3TfG'></small><noframes id='M3TfG'>

  1. <i id='M3TfG'><tr id='M3TfG'><dt id='M3TfG'><q id='M3TfG'><span id='M3TfG'><b id='M3TfG'><form id='M3TfG'><ins id='M3TfG'></ins><ul id='M3TfG'></ul><sub id='M3TfG'></sub></form><legend id='M3TfG'></legend><bdo id='M3TfG'><pre id='M3TfG'><center id='M3TfG'></center></pre></bdo></b><th id='M3TfG'></th></span></q></dt></tr></i><div id='M3TfG'><tfoot id='M3TfG'></tfoot><dl id='M3TfG'><fieldset id='M3TfG'></fieldset></dl></div>
    <legend id='M3TfG'><style id='M3TfG'><dir id='M3TfG'><q id='M3TfG'></q></dir></style></legend>
    1. <tfoot id='M3TfG'></tfoot>
    2. iOS 框架包的路径

      时间:2023-05-17

      1. <tfoot id='EgfkL'></tfoot>
          <tbody id='EgfkL'></tbody>

          <legend id='EgfkL'><style id='EgfkL'><dir id='EgfkL'><q id='EgfkL'></q></dir></style></legend>
            <bdo id='EgfkL'></bdo><ul id='EgfkL'></ul>
            1. <i id='EgfkL'><tr id='EgfkL'><dt id='EgfkL'><q id='EgfkL'><span id='EgfkL'><b id='EgfkL'><form id='EgfkL'><ins id='EgfkL'></ins><ul id='EgfkL'></ul><sub id='EgfkL'></sub></form><legend id='EgfkL'></legend><bdo id='EgfkL'><pre id='EgfkL'><center id='EgfkL'></center></pre></bdo></b><th id='EgfkL'></th></span></q></dt></tr></i><div id='EgfkL'><tfoot id='EgfkL'></tfoot><dl id='EgfkL'><fieldset id='EgfkL'></fieldset></dl></div>

              <small id='EgfkL'></small><noframes id='EgfkL'>

                本文介绍了iOS 框架包的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我正在开发一个带有一些数据文件的 iOS 框架.要将它们加载到 Dictionary 我会这样做:

                I am working on a framework for iOS, which comes with some datafiles. To load them into a Dictionary I do something like this:

                public func loadPListFromBundle(filename: String, type: String) -> [String : AnyObject]? {
                    guard
                       let bundle = Bundle(for: "com.myframework")
                       let path = bundle.main.path(forResource: filename, ofType: type),
                       let plistDict = NSDictionary(contentsOfFile: path) as? [String : AnyObject]
                    else { 
                       print("plist not found")
                       return nil 
                    }
                
                    return plistDict
                }
                

                如果我在带有框架的游乐场中使用它,它会按预期工作.

                If I use this in a playground with the framework, it works as intended.

                但是如果我使用嵌入在应用程序中的框架,它就不再工作了,路径"现在指向应用程序的捆绑包,而不是框架.

                But if I use the framework embedded in an app, it doesn't work anymore, the "path" now points to the bundle of the app, not of the framework.

                如何确保框架的捆绑包被访问?

                How do I make sure that the bundle of the framework is accessed?

                上面的代码驻留在框架中,而不是在应用程序中.

                the code above resides in the framework, not in the app.

                上面的代码是一个实用函数,不是结构或类的一部分.

                the code above is a utility function, and is not part of a struct or class.

                推荐答案

                使用Bundle(for:Type):

                let bundle = Bundle(for: type(of: self))
                let path = bundle.path(forResource: filename, ofType: type)
                

                或通过 identifier(框架包 ID)搜索包:

                or search the bundle by identifier (the frameworks bundle ID):

                let bundle = Bundle(identifier: "com.myframework")
                

                这篇关于iOS 框架包的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Xcode 5 框架/库搜索路径绝对地址 下一篇:使用 Xcode 调试库

                相关文章

                <i id='7Veti'><tr id='7Veti'><dt id='7Veti'><q id='7Veti'><span id='7Veti'><b id='7Veti'><form id='7Veti'><ins id='7Veti'></ins><ul id='7Veti'></ul><sub id='7Veti'></sub></form><legend id='7Veti'></legend><bdo id='7Veti'><pre id='7Veti'><center id='7Veti'></center></pre></bdo></b><th id='7Veti'></th></span></q></dt></tr></i><div id='7Veti'><tfoot id='7Veti'></tfoot><dl id='7Veti'><fieldset id='7Veti'></fieldset></dl></div>
                <legend id='7Veti'><style id='7Veti'><dir id='7Veti'><q id='7Veti'></q></dir></style></legend>

                <small id='7Veti'></small><noframes id='7Veti'>

                    <tfoot id='7Veti'></tfoot>

                    • <bdo id='7Veti'></bdo><ul id='7Veti'></ul>