Software Architect / Entrepreneur

Software Architect / Entrepreneur

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

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.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

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, visit the Swift documentation.

Email Notifications

Never miss a post again! Get my latest articles delivered directly to your inbox and be the first to know about my upcoming course!

Email Notifications

Never miss a post again! Get my latest articles delivered directly to your inbox and be the first to know about my upcoming course!

🙏

Great Choice!

Thanks for enabling notifications! Don’t worry, I hate spam too and I won’t ever disclose your contact information to 3rd parties.