Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode project with multiple targets and multiple assets catalogs

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?

like image 571
madelman Avatar asked Apr 12 '16 09:04

madelman


People also ask

How do I add an asset catalog in Xcode?

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.

What is an asset catalog?

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.

What is assets Xcassets?

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.


1 Answers

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.

First Step

Second Step

Third Step

like image 186
ZeroOne Avatar answered Oct 13 '22 07:10

ZeroOne