0

In order to support multiple brands, i am keeping the images and assets in bundle. Each bundle has different images and color codes based on brand. So how to fetch images and color code inside of a custom bundle.

KP26
  • 283
  • 3
  • 14

1 Answers1

0

If its syntax you are after, it here -- Load image from bundle with iOS

Specifically --

UIImage(named: <#T##String#>, in: <#T##Bundle?#>, compatibleWith: <#T##UITraitCollection?#>)

UIColor(named: <#T##String#>, in: <#T##Bundle?#>, compatibleWith: <#T##UITraitCollection?#>)

If you are concerned with the architecture --

  1. I'd create an enum with all the Brands that you support with their corresponding Bundles as a computed property. Then I'd add simple methods to get image & colour based on brand in extensions of UIColor & UIImage (so you want have pass bundle every time). Those extension methods (returning colour & image) will use the methods mentioned above along with current Brand (assuming it's a global).

  2. If current brand is not global then you can write a helper struct or something that has the current brand & will provide methods that return colour & image.

  3. Pass bundle every time to the methods above.

I'd go with (1)