Path to bundle of iOS framework

后端 未结 4 1206
耶瑟儿~
耶瑟儿~ 2020-12-14 15:52

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 loadP         


        
4条回答
  •  抹茶落季
    2020-12-14 16:29

    Use Bundle(for:Type):

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

    Update:

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

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

提交回复
热议问题