Use different packages for different builds iOS - 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 )

Related

Xcode: External build configuration for framework target

We have a Filters framework that contains many image processing filters (written in Swift and Metal) and the resources they require (like ML models and static images). But not every app we have uses all the filters in Filters. Rather we want to only build and bundle the required filters and resources that are needed by the app.
The only way we can think of to achieve that is to create different framework targets in Xcode, one for each app. But that would require that the Filters framework project “knows” all of its consumers (apps) and we would rather like to avoid that. Especially since the filters are in a separate repository.
Is there a way to, for instance, pass some kind of configuration file to the framework that is used at build time to decide which files to build and bundle?
You can use Target Membership to assign files into specific targets. See image below.
Make sure you are on the File Inspector tab on the right side of Xcode. Select the files you want to limit to a target and in the Target Membership area, you can select which target the selected file belongs to or don't belong to. For public resources, make sure to select public for the visibility scope.
For files that don't require compilation, e.g. image files, once you've selected the target membership, the file will be automatically added to the Build Phases' Copy Bundle Resources area.
Alternative One
Alternatively, you can use add a Copy Files Phase in the Build Phases. With the Copy Files Phase, you can copy files to subdirectories instead of the root of the framework bundle.
Alternative Two
Yet another way is to add a Run Script Phase in the Build Phases. The script can be in any language but usually shell script. You can do whatever you need in the script including compiling code manually but you need to know where the files goes by using environment variables and placed the files in the correct location. I think this will be the most manual and most hassle to use for selecting files based on targets.
Alternative Three
If you really want to go fancy, you can even break down all the components into targets and use Aggregate target to tie the different components into the target you are building for. I would not recommend this usually and reserve this for very special needs that other methods could not achieve.

How to use different assets with same name using multiple targets

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.

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.

Assets using targets with Xcode

I'm working with an iOS app with múltiple targets and at this moment, I have a critical doubt.
The project has two targets, target A and B, and each target has different set of images.
My question is:
If I upload the target A to iTunes Connect, this target will contain also the images of the target B, or this target (A) only will contain her images?
Target A and Target B would have the same images only if you set it up as such. Each target can have its own set of source files and assets. If you look select items (whether it be source files, frameworks, or other asset files) and have the File Inspector on, you'll see something called Target Membership. This indicates which target it belongs to.
When you Add File(s), there is also a dialog that indicates which targets to add it to.
The Build Phase of the target will also show you the files that are compiled as well as files that are copied into the binary and the libraries used to link.
Note there are multiple ways to add/remove files from the target.

Different Builds for the same application

I am developing a product for a client and I have a problem.
The application will be sold to various customers only changing the interface the same (images - images.xcassets).
What is the best way to manage this? I do not want to duplicate the project for each client, but a way to manage builds of each, and the only change will be the bundle id and images.
My project is IOS 6.1>
Thank you.
As Wain says, set up multiple build targets. Select your project in the navigator area, then select the current target in the list of targets, right click on it, and select "duplicate". That will create a new target that does exactly the same thing.
You'll need to change the bundle ID, app name, etc.
Then you would select your current asset catalog, select the view menu>utilties>file inspector and set the target membership to just the current target. Select your new target, add a new asset catalog, and set it's target membership to only include the file in the new target.
Repeat this process for each version of the app that you want to build.

Resources