I have a project with two targets: target A and target B. This targets generate app which are "equal" but whit different skins (different colors and images)
For this, the project has two Asset Catalogs, which are identical but have different images insides. Each Asset catalog is assigned to the corresponding target.
This works perfectly and I can generate both applications, but while editing the Storyboards and assigning the images I can only see the images from the first Asset Catalog.
Is there any way to see or "preview" the storyboards with the different Catalogs?
If you don't already have an asset catalog in your project, you can create one by right-click on your project and choosing New File. From "iOS" choose "Resource" then Asset Catalog, then click Next and name your catalog. You can now select your new asset catalog in Xcode, and drag pictures directly into it.
An asset catalog is a type of file used to organize and manage different assets and image resolutions used by your app's user interface.
xcassets Catalog in Xcode. An asset catalog, simply put, is a single folder in Xcode that you use to organize your app's images, icons, colors, and more. Instead of adding individual images to Xcode's file organizer, you add assets neatly organized in a single catalog.
We can have multiple asset catalogs.
We are having ‘Alphabets’ project and in this project, we are having three targets - three applications. A, B and C.
Now default one is ‘Assets.xcassets’ which is in the main directory.
For ex: My Projects/Alphabets/Assets.xcassets - All Targets
You can create as many as xcassets in hierarchy also. Listed some examples below.
My Projects/Alphabets/One/A/1A.xcassets - A Target My Projects/Alphabets/Two/B/2B.xcassets - B Target My Projects/Alphabets/Three/C/3C.xcassets - C Target
When you are adding any resource to this xcassets, make sure that the name which is displayed in Xcode and the actual image name when you have added it are same. After that you will be able to user it using the image name method.
if target == "A" {
let imageView = UIImageView(image: UIImage(named: "a"))
}
if target == "B" {
let imageView = UIImageView(image: UIImage(named: "b"))
}
if target == "C" {
let imageView = UIImageView(image: UIImage(named: "c"))
}
Please check screenshots attached here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With