Home > other >  Dynamic content for app with multiple targets
Dynamic content for app with multiple targets

Time:08-05

I'm looking to change a background color of a view, depending on the selected target.

In this case Imagine I have a travel app, where the base application is the same but each city is a separate target/app which varies slightly from city to city. So London would be Green and New York would be blue, for example.

How can I best achieve this? Currently I'm unsure how to get/retrieve the app target. So I can use it as a parameter in a switch case for changing the color of my view.

Also any examples, tips or guides on creating apps with a single codebase and multiple targets, is much appreciated. As I'm struggling to find much on the subject. Thank you in advance!

CodePudding user response:

you can use something like that to get the target name if your app color will switch depending

1 - target name

var targetName = Bundle.main.infoDictionary?["CFBundleName"] as! String

2 - target type like macOS or iOS or iPadOS you should use compiler directives

#if os(macOS)
// compiles for macOS
#elseif os(iOS)
// compiles for iOS
#elseif os(tvOS)
// compiles for TV OS
#elseif os(watchOS)
// compiles for Apple watch
#endif
  • Related