Is there any way to create a project/application which will have multiple targets.Its same as how we create multiple targets for an iPhone application in XCode.Basically I have an app which has to be made for different targets, with almost all the similar functionalities but with little change.
You can use Configuration Manager to add additional configurations to the list of Debug and Release. Then for each configuration go to Project/Properties/Build/Conditional compilation symbols and add a symbol used with your configuration or target, eg. make it SILVERLIGHT;WINDOWS_PHONE;CUSTOMVERSION1
Then in your code you can say
#if CUSTOMVERSION1
Debug.WriteLine("This is a CUSTOMVERSION1");
#else
Debug.WriteLine("This is not CUSTOMVERSION1");
#endif
Otherwise - if you want to make bigger changes - you would create another project and link files from one project to another project - project/Add/Existing Item//Add As Link(an option in the "Add" button menu). You can then add more files or add different versions of these files as needed. You could use Project Linker to do it faster.
Related
I have a project in Xcode (swift) and I want to build it in two ways. a build with a framework (embedded in project) and another build without that framework.
Is there any way to do this with minimum changes for each update?
I means something like if #available statement which determine whether a particular framework is embedded in project or not.
something like:
if ... {
import framework
}
Finally, I found my solution.
In this case we should do four main tasks:
creating a scheme for separate builds
defining an Active Compilation Condition
excluding the frameworks we want to remove from build.
putting depended codes in #if scope.
First of all, we need to create two build configurations by duplicating and renaming debug and release build configurations (In this case, I named those as Debug_no_charkhune and Release_no_charkhune). For first step, with choosing main scheme and clicking on duplicate scheme in edit scheme page our new scheme is ready. just remember to change its name and build configurations in all tabs with new build configurations. For second step, we should go to Build settings tab in project setting page and set Active Compilation Condition values for wanted schemes. (In this case I defined CHARKHUNE as a condition).
Now we need to exclude unwanted frameworks in new scheme. for this, we should add framework name as a string in Excluded source file names section in project's builds settings like image:
Now we're ready for it. we should put codes that are related to excluded framework in an if statement like this:
#if CHARKHUNE
import charkhunePayment
#endif
At last. thanks #Cristik and #dfd for their advices.
Hope you enjoy ;)
To link binaries to you framework you can from build phase add your needed libraries to your project .. but what if I need to make some thing specific for example I need to customise my framework by adding or deleting binaries.. foe example I want lite version and full version so I need always to delete and add these binaries from "Link binary.." tab
Is there any dynamic way like to make different configuration files or some thing?
You'd need to create 2 Xcode targets, one for lite and one for pro, which compile the same source files and link to mostly the same frameworks etc.
You can also add compiler constants to the Build Settings of these targets, which will allow the common source files to behave differently between these target "products".
I have a project for a iOS app and wan't to make two different apps from it. I want the apps to have different skins and want the two apps to connect to two different web services. So I want a base app project from which I can select which to build.
I essentially want to fork a project but don't want to maintain two projects
Also they have to be able to be installed on the same device at the same time.
Is there some sort of "good practice advice" on how to do this?
I would also be interested in a similar solution for android projects
A project with different targets will do:
They will allow you to set different Info.plist for each target (which allow you to set different bundle ID, allowing two apps installed at the same device).
It also allows you to set C flags for each target (which allows you to put conditional statements based on the flag in your codes)
You can have the lines that should be executed in the target, in this example the copy target, with ifdef macro:
#ifdef COPY_VER
//lines of code to be executed for the copy target
#else
//lines of code to be executed for the other target(s)
#endif
I have 3 applications that share a lot of functionality. It is only the content and styling changes between them.
Instead of simply duplicating the project for each app, is there a way to make a "base" application and then have the 3 applications extend this?
Simply duplicating the project would be horrible to maintain, whereas extending a "base" would allow them to all update simultaneously.
I know you could create the project and then copy all files from the old project into the new. This would keep the files up-to-date, however if any files were added or removed, you would have to manually do that.
Have one base project that uses multiple targets. Each target can include a subset of the files in your main project, and/or add their own independent files. Each target can also have its own set of preprocessor defines set up in the build configuration.
You can add more targets to your project in Xcode.
Create a project that builds a static library for the reusable components. You can use an Aggregate target to package any associated resources, such as nib files, storyboards, images, etc.
Your app projects can all then consume the static library and resources. Any changes to the static library will be available to all the dependent projects.
I'm including a 3rd party library (sources) with my static library. It it intended for device only (since it includes some ARM assembly routines) and I do not wish to build it for the simulator (I just want my app to compile there so I can test the GUI).
Creating another target for simulator only is not an option since my projects reference my library as a dependency and it would be a nightmare to maintain.
Adding #if (TARGET_OS_IPHONE) for those files is not an option as well since these are not my original sources and I would like to update them easily for updates (there are more than 200 files there and I do not with to modify all of them)
I'm looking for a way (similar to #if (TARGET_OS_IPHONE) in source files) which will work from the IDE itself (so I can exclude a file from the actual build process based on my target architecture). The only thing I found is an option to exclude/include a file from a target - but not for a specific architecture.
Is there a way to set architecture conditions per specific files?
Your best bet would be to separate the third party library into a new target that builds it as a static framework. Set it as a dependency for your project, and then set the static framework to be conditionally linked as described by Apple here: http://developer.apple.com/library/ios/documentation/Xcode/Conceptual/ios_development_workflow/115-Configuring_Applications/configuring_applications.html#//apple_ref/doc/uid/TP40007959-CH19-SW7
You can add a new target by selecting the Project in the project navigator and then hitting the Add Target button at the bottom of the Editor pane. You can setup a cocoa touch static library and then assign the relevant .m or .c files to belong only to that target. Then select your app's target and add the static framework in the "Target Dependencies" section of the Build Phases tab.
You can conditionally include/exclude files in Xcode using EXCLUDED_SOURCE_FILE_NAMES based on sdk. For example:
EXCLUDED_SOURCE_FILE_NAMES[sdk=*simulator*] = something.cpp something_else.cpp
See Conditional Compilation article for more details