Best Practice: How to handle code differences for iOS App when creating free and paid version?

落花浮王杯 提交于 2019-12-04 16:42:29

If you branch or copy the project you're creating a maintenance nightmare for yourself down the road.

Create a separate target in the same project, specific differences can be handled via #ifdef blocks in the code. Add defines to each target to specify whether you're building paid or free versions.

== ADDED ==

To define the per target symbols go to build setting for the target, scroll way down until you find the Apple LLVM 5.1 - Preprocessing block, the change the target-specific settings to add your desired symbol (FREE_BUILD=1 or PAID_BUILD=1 e.g.)

To add target specific code you can then use that defined symbol in your code as:

// some code here
#if FREE_BUILD
    // Some code that only gets compiled for the free target here
#elif PAID_BUILD
    // Some code that only gets compiled for the paid target here
#else
    // Just in case because I'm a paranoid sob
    #error Must define FREE_BUILD or PAID_BUILD
#endif
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!