November 27, 2020 · Swift Bite-Sized Knowledge

Bite-Sized Knowledge: Similar versions a Swift app, but one shared code base

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket

If you have an app that has slight variations, but is mostly the same, you could use a combination of multiple schemes and compilation conditions. For instance, you could have two apps with slightly different onboarding experiences, but for the most part they're the same.

If you look at your Build Settings there's something called "Active Compilation Conditions". Right there is essentially a build label you could use to conditionally include/exclude code once you do a build.

For instance, you could use #if to push different views depending on the version of the app like so:

#if APP_MAIN
	let fullVc = FullExperienceViewController.instantiate(coordinator: self)
	navigationController.pushViewController(fullVc, animated: true)
#endif

#if APP_LITE
	let liteVc = LiteExperienceViewController.instantiate(coordinator: self)
	navigationController.pushViewController(liteVc, animated: true)
#endif

As I mentioned above, for each scheme you'd have their respective compilation labels under "Active Compilation Conditions": so one would have APP_MAIN and the other would have APP_LITE.

And there you go. That's all you need.

For more information on what conditions you can use, have a look at https://docs.swift.org/swift-book/ReferenceManual/Statements.html#ID538.

Subscribe by Email

Get my latest content straight to your email

    We won't send you spam. Unsubscribe at any time.
    Powered By ConvertKit
    If you have any questions about this article