How to build a free version from a paid version without duplicating the Xcode 4 project?

后端 未结 1 1158
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-02 01:39

I\'ve heard rumors that it is possible to build different variations of an app without duplicating Xcode projects, by using targets and conditional compilation instructions like

1条回答
  •  一生所求
    2021-02-02 02:33

    Open your project in Xcode and select the top-level item in the Project Navigator. You should see the list of targets for your project.

    Create a new target for the free version of your app. An easy way to do this is to control-click a current target that's similar to what you want and duplicate it.

    Select your new target. In the Build Phases tab you can control which source files will be built as part of this target and which resources are copied for it. In the Build Settings tab search for Preprocessor Macros and add a new one, for example MYAPPLITE=1, for all build configurations. You can then do conditional compilation in your code with something like:

    #ifdef MYAPPLITE
        [self loadBoringFeature];
    #else
        [self loadGreatFeature];
    #endif
    

    Finally, select Edit Scheme... from the Product menu. A new scheme should already have been created for your new target. You can rename it in the Manage Schemes sheet if you want. You can control specific settings for building, running, archiving etc. the new target here.

    To switch between building the free version or the paid version you just change the active scheme.

    The only real caveat is that you need to keep the settings for your new target up to date.

    0 讨论(0)
提交回复
热议问题