In this post, I’m going to illustrate an approach I’ve used to add a touch of interactivity to a project build. Furthermore, using config files decrease source control merging conflicts.Apple’s Mack truck of an IDE, Xcode, doesn’t give you a lot of room to mess with its build process, but there are a few options for customization. xcconfig files is a more scalable option than having multiple build targets. Xcode Build Configuration Files manage the complexity that exists for apps that require multiple build variants. Guard let hostname = (forInfoDictionaryKey: "API_HOSTNAME") as? String,įatalError("Developer Error: Unable to read API_HOSTNAME from info plist") func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: ?) -> Bool Add the API_HOSTNAME key to both info plist files, and for the value make it the build setting variable $(API_HOSTNAME). The simplest thing to do is copy it into our ist file since there is an easy to use API to access those values. File: īuild settings and their values are only available at build time, so we need to have the value of this new, custom build setting – API_HOSTNAME – copied somewhere we can access it at runtime. xcconfig files with the values that are dynamic based on staging or production. Our final step is going back and modifying our. You should now be able to build and run a staging or production version of your app using the scheme picker. Profile and Archive should use a “Release” setting. Run, Test, and Analyze should use a “Debug” setting. From here, each of the Products (Run, Test, Profile, Analyze, and Archive) can use a specific build setting. Click the gear icon and choose “Duplicate.” Click-and-hover to rename each scheme: “My App (Staging)” and “My App (Production)”.ĭouble clicking a scheme will take you to the Scheme Editor. Our second to last step is get the build schemes setup so we have an easy way to pick between building staging or production.Ĭlick the scheme picker and choose “Manage Schemes…” Click on the existing scheme for your app. Rename the two “Debug” configurations “Staging (Debug),” and “Production (Debug).” Rename the two “Release” configurations “Staging (Release),” and “Production (Release).”įor each of these configurations, click the disclosure triangle and associate the appropriate. Make a new configuration based on Debug and make a new configuration based on Release. Click on the “Info” tab.Īs you can see, the default Configurations in a new Xcode 11.2.1 project are “Debug” and “Release.”Ĭlick the plus button to create a new configuration, and you’re prompted to duplicate one of the existing configurations. Click on the project in the column that lists projects and targets. Click on the project in the Xcode File Navigator. xcconfig files setup, we need to tell the Configurations to use them. We’ll need to make sure we have two ist files in our app: ist for production and ist for staging. INFOPLIST_FILE is the ist file that is used by the app bundle for things like the App’s Display Name and Privacy Descriptions. In our example, we’re using .myapp for staging builds, and for production builds. PRODUCT_BUNDLE_IDENTIFIER is commonly referred to as the “Bundle ID.” We see this setting all over App Store Connect and what Apple platforms use to uniquely identify an application. To build two apps that behave differently from the same target, the INFOPLIST_FILE and PRODUCT_BUNDLE_IDENTIFIER build settings are what we need to focus on. Each file specifies build settings that apply to the different ways we want the target built. You can start to see how these build configuration files support our goal. PRODUCT_BUNDLE_IDENTIFIER = .myappĪSSETCATALOG_COMPILER_APPICON_NAME = AppIcon-QAĪSSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage-QA // File: ĪSSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage-QA SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG GCC_PREPROCESSOR_DEFINITIONS = DEBUG=1 $(inherited) ![]() Xcode’s “New File” template chooser has a “Configuration Settings File” option. Create and Setup Xcode Build Configuration Files My App will communicate with the production backend, whereas My App QA will communicate with the staging backend. The goal is to have one target that outputs both My App and My App QA based on which build scheme is selected. Xcode Build Configuration Files allow us to create builds of an app that work differently with a backend that has staging and production environments.
0 Comments
Leave a Reply. |