Xcode project with multiple targets and multiple a

2020-02-05 04:33发布

问题:

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?

回答1:

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.