12

I have one app that has 2 variations that only differ in branding. For each version I have an AppIcon and LaunchImage in an asset catalog. I've created a different target for each version. In the second version when I try and select AppIcon in the second asset catalog it just defaults to the first one. Removing the first asset catalog seems to resolve it but I would prefer a less 'hacky' solution.

Mark Horgan
  • 3,243
  • 4
  • 27
  • 28
  • I don't know if you did this or not, but there should only be one catalog per target (in your case). You can change which target gets which catalog in the project's build settings. – Scott Berrevoets Oct 21 '13 at 13:30
  • The 2 asset catalogs are in different targets, though both show up in the General section (App Icons & Launch Images) of both targets. – Mark Horgan Oct 21 '13 at 13:40
  • I've discovered that if you rename the conflicting assets in the 2nd asset catalog it seems to work, i.e. rename AppIcon to AppIcon1 – Mark Horgan Oct 21 '13 at 13:50
  • Possible duplicate of [Xcode project with multiple targets and multiple assets catalogs](https://stackoverflow.com/questions/36568497/xcode-project-with-multiple-targets-and-multiple-assets-catalogs) – gparyani Oct 10 '18 at 10:28

7 Answers7

8

I think the best solution I've come up with so far is to rename assets in subsequent asset catalogs. For example you might have 2 asset catalogs that contain assets named AppIcon and LaunchImage. In the 2nd asset catalog I've renamed AppIcon and LaunchImage to AppIcon1 and LaunchImage1. So now I can select them in the 'General' section of the target's build settings.

Mark Horgan
  • 3,243
  • 4
  • 27
  • 28
  • If you place 2 different images with the different names each into its one of 2 asset catalogs, and call in code image that should not be included into your target, you'll see that it is unexpectedly there. How to avoid that? – Eugene Dudnyk May 05 '14 at 12:13
  • 2
    Found solution - my problem occured because I am using CocoaPods, and their script compiles all .xcassets folders. Solution is here: http://stackoverflow.com/questions/19488580/asset-catelog-issue-with-multiple-targets. – Eugene Dudnyk May 05 '14 at 12:47
  • @DisableR I'm only renaming AppIcon and LaunchImage so that you can select it from the drop-down in the General section of the target's settings. The other images can be left unchanged. – Mark Horgan May 07 '14 at 09:25
2
  1. Use the same asset catalog for both targets.
  2. Check that it is included on both targets (check target membership using file inspector).
  3. On each target select the appropriate name of asset (icons).

This shall work, I'm using it with 8 targets so...

Btw, I discover that sometimes launch-image isn't working when using few targets so you may need to duplicate then select it (Xcode bug).

Idan
  • 9,880
  • 10
  • 47
  • 76
  • 2
    Are you saying that you have one asset catalog that contains all the assets for all the targets i.e. AppIcon for the 1st target, AppIcon2 for the 2nd target? If so, I'm not sure that is a good idea. Each app will contain assets it doesn't use and the launch images for the iPad are large. – Mark Horgan Oct 22 '13 at 09:16
  • @MarkHorgan Yes that's what I have. I think you are right but other method makes too many issues for me...Till Xcode 5 would be better... – Idan Oct 22 '13 at 10:21
  • My mistake was not included on both targets. – Beto Mar 26 '14 at 15:44
2

In my case I am using cocoa pods. The cocoa pods script Pods-resources.sh somehow caused the problem. removing the asset parts from the script solved the problem.

Make sure to clean your project and delete derived data folder.

Parts to be deleted can be found here:

https://stackoverflow.com/a/21309102/832111

Community
  • 1
  • 1
d.ennis
  • 3,445
  • 2
  • 28
  • 36
  • After removing those sections from the `Pods-resources.sh`, the small window where you check targets for each asset catalog doesn't appear. Is this expected? If so how do I set them now? – Isuru Jun 18 '14 at 04:26
  • This! Take a look at this CocoaPods issue for workarounds. The post_install hook by jinthagerman is a good solution: https://github.com/CocoaPods/CocoaPods/issues/1546 – Form Aug 06 '14 at 03:28
1

After much frustration, I have clean, successful, separate images assets. Here's what worked for me:

  1. I used XCode to create an image catalog for the first target (File, New, File, Asset). It has a membership for that target only. As Mark Horgan suggested, I named the internal appIcon & launchImages, if only to make it easier for myself.

  2. Next, I deleted that catalog from my project using the option to remove references.

  3. I repeated step 1 and created an image catalog for the 2nd target. It has a membership for that 2nd target only. Assigning the catalog to my target was tricky because XCode only offered "Don't Use Image Catalog" as an option. I choose that option, and then XCode offers "Use Asset Catalog". I chose my new catagot. Again I named the internal appIcon & launchImages to reference the 2nd target, so I could recognize it.

  4. As in 2, I removed the catalog with a remove references delete.

  5. Departing XCode for a moment, I opened a Finder window and located my two different images.xcassets files which had been put in different directories by XCode. I renamed those files to each reference their target. (I also moved them into the master folder, but of course that's a preference.)

  6. Back in XCode, I (re)added the xcassets files, one at a time, ensuring they were appropriately added to their target and copied to resources.

  7. Then in XCode I selected each target and used the General tab to properly specify the image catalog for each target.

user216661
  • 323
  • 3
  • 14
1

I'm running with several targets where each has their own asset catalog file, with both AppIcon, LaunchImage and a custom I use in storyboard for backgrounds.

It sounds like the same problem I had, when selecting the asset catalog for App Icons and Launch Images it took the wrong one when building. I solved it by modifying the "Target Membership" for each assets catalog, the .xcassets file. It's set so each xcassets file only have the target it's related to. Thereby only one target is selected per asset catalog. Now it's the right AppIcon and LaunchImage that's available for each target.

Priebe
  • 4,942
  • 3
  • 24
  • 38
0

I used @user216661 solution, but in my case I didn't have to do steps 2-7.

I created an asset folder with specific name for specific target (in my case, one asset folder per target). Then I added the images to those xcassets folders by dragging & dropping them from Finder. The same for icons and launch images. I didn't have to customize graphics names for each target.

In this solution, you don't store any graphics outside asset folders.

Wladek Surala
  • 2,590
  • 1
  • 26
  • 31
0

How about just modify the assets in build setting option.For me,it worked.

frank
  • 2,327
  • 1
  • 18
  • 20