How to use different assets with same name using multiple targets - ios

I'm trying to build an app with multiple targets, each should have different asset versions. The business requirement is to have the same app but with different branding assets. I don't want to copy and paste the project and change icons manually because this won't be efficient.
As an example, I have a logo in the assets catalog, both Target X and Target Y need to see the asset, but both targets need to see a different version of the asset.

You can do this by creating additional Asset Catalogs, these can be named accordingly, they will need to be added to your required target, Target Membership.
Having different collections you are able to have the same asset names and the targets will work as expected.

Related

What's difference between Assets.xcassets and images.xcassets?

When I new a xcode project, there was a image folder by defalut, I wanna to know that is there any difference between them? Is Assets.xcassets newer?
What is Asset?
Asset catalogs to organize and manage the different asset types and image resolutions used by your app’s user interface.
You can have multiple asset catalogs in your project and within each catalog, multiple sets of assets. In addition, you can organize sets into folders.The common types of sets you can add to a catalog are image, data, and texture sets.
Now you understand that image asset is one of the asset catalog.
It will automatically created by Xcode when creating new projects.
Common use of Asset catalog :
In particular, use asset catalogs to manage images that are required
to launch your app on a device and submit your app to the App Store.
As above statements from apple there are multiple asset types are available.You can create catalog for each type if you want.
Asset types
You can get more info from help.apple.com
Not really sure but I think since Xcode 7 you have this new Assets.xcassets catalog to store several types of resources, not just images as you can have sounds, images, fonts and movies in your project.

Use different packages for different builds iOS

I have a package named assets where I store my database and media files. I want to publish my application and use source control, but I need to use different assets for each publication. How can I achieve that in xcode ?
Create different Targets for the builds you need (right click on a target and duplicate it is the easiest way ) then change the Target Membership of the assets required for the specific targets you need ( target membership can be seen on the right hand pane when you select an asset and this will give you the ability to checkbox assets against the Targets )

Xcode: Exclude images in build from asset catalog according to preprocessor flag

I have two apps that share almost everything except that one shows ads according to a preprocessor macro that is configured on the Build Settings tab.
Now, following the same rule, I need to exclude images from the Asset Catalog, so this way the app with ads doesn't include things that it shouldn't, but I don't know how to do it. Any guidelines?
Thanks
Since you have two targets in your project, the simplest solution is to have three or more image assets (xcassets) in your project.
One with images common to both targets, one with images specific to target A, and one with images specific to target B.
Then ensure that the two target-specific assets are only targeted to their respective project target.

One Project For Multiple Applications in XCode

I am trying to use the approach of having a single project that uses different targets with different plist files. However, each target has a different set of launch and icon images. I cant however use a duplicate set of these since adding a duplicate image when the same name gives the error that its already in use. Is there anyway around this in xcode?
To save the file, either provide a different name, or move aside or delete the existing file, and try again.
You should use Xcode 5's assets catalogs. You can define a different assets catalog for each target, and in each assets catalog you can define different launch images. Names are handled by the content generator.
You can mix asset catalogs, so you can have, for example, one shared catalog for shared images, and individual ones for each different target, where you can have distinct icons and launch images.
OK, so I have changed my approach and found the easiest and a simple solution which I ignored before. All you have to do is keep the file names same but keep the files in different folders. And when adding them to project, check the target to which the files belong to and uncheck other targets. See the image.

An iOS app with multiple brandings

I have an iphone app working just fine - it basically just displays news from a feed, but now we want to have a second app that is a clone of the first but branded a different way and displaying news from a different feed - the xml feed and the graphics/colors would be the only difference.
I'm trying to not duplicate any effort. I can easily set a define and build the app using different colors and images and the xml feed url with one codebase. But what is the preferred way to do this so that I can make a change to some common code and easily rebuild both apps and get them updated in the app store without maintaining separate xcode projects, separate files, etc?
You can do this easily by adding a new target to your project.
Create unique branded assets and configuration files with identical names, but keep them in different folders. When you're ready, add each folder to the project and set the "Target Membership" to the appropriate target. If you make a mistake, you can change it in the File Inspector pane.
When you build a specific target from the shared codebase, only those resources will be bundled with the app. As long as the filenames are identical, it should work.
You can use one project with more then one target. For each target you can add different resources (Info.plist, icon, etc.).
XML feed can be defined in settings.bundle (which also can be dependent on the target).
Layout you can read from dictionary, which also should be dependent on the target.

Resources