Load image to uiimageview based on the selected target in Xcode

566 views Asked by At

I'm trying to create two applications from same codebase. These application will have same functionality but different logos, app name etc. I have created two targets with different bundle Ids so now I get unique apps when running each target.In my app, I have a viewcontroller with an UIImageView. Now I want to assign an image to UIImageView based on the running target. So I created two assets folders.

  • Target1 -> Assest1 -> logo.png
  • Target2 -> Assest2 -> logo.png

logo.png is different file with same name.

How can I assign the correct logo.png to uiimageview based on the running target? Your help is appreciated.

1

There are 1 answers

0
rickramirr On

Ensure that your asset is in the correct target an then use the following method:

UIImage(named: "example", in: Bundle(for: YourClass.self), with: nil)

To obtain your bundle you could use your class to refer to your bundle:

Bundle(for: YourClass.self)