-2

I need a picture to appeare in a framework. The only way i found needed that i know the name of the app it is in. Is there another way to get assets into your framework? (For getting this posted:

  • my background search didnt help)
  • 2
    Why can't you use the name of your framework? Details matter. Like an app, a framework has a bundle name. Use that. If it's a third party framework, post more details. –  Apr 23 '21 at 21:26
  • 1. I could use the name of the framework but not the apps name it I will be nested in, and that was the only way I found. – Swift lover Apr 24 '21 at 07:57
  • 2. It would be nice to get an xcasset for the dark mode pictures (but not needed) – Swift lover Apr 24 '21 at 07:58

1 Answers1

0

Almost 5 years ago I posted this answer. It contains two pieces of code to pull out an asset from a Framework's bundle. The key piece of code is this:

public func returnFile(_ resource:String, _ fileName:String, _ fileType:String) -> String {
    let identifier = "com.companyname.appname" // replace with framework bundle identifier
    let fileBundle = Bundle.init(identifier: identifier)
    let filePath = (fileBundle?.path(forResource: resource, ofType: "bundle"))! + "/" + fileName + "." + fileType
do {
    return try String(contentsOfFile: filePath)
}
catch let error as NSError {
    return error.description
}

So what if your framework, which needs to know two things (app bundle and light/dark mode) tweaked this code? Move identifier out to be accessible to the app and not local to this function. Then create either a new variable (I think this is the best way) or a new function to work with the correct set of assets based on light or dark mode.

Now your apps can import your framework, and set things up in it's consumers appropriately. (I haven't tried this, but in theory I think it should work.)