iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🍎
Configuring Xcode Schemes for Different Execution Modes
There are times when you want to change the behavior of Swift during debugging or testing, such as changing the API endpoint.
You can achieve this by using Schemes.
Creating a New Scheme
- Go to Product, Schemes, and then Manage Schemes...
- Create a new Scheme.
- You can enable debugging by specifying the app in the Executable field under Run.
If you check Shared when adding it, you can include it in Git.
Code to change behavior only for a specific scheme:
Build Configuration
- Click the root of the project tree.
- Select PROJECT.
- Select Info.
- Add a configuration from Configurations (copy from Debug or Release).
Active Compilation Conditions
- Click the root of the project tree.
- Select TARGETS.
- Select Build Settings.
- Type "Active Compilation Conditions" in the search bar.
- Since it is registered with the name you created in Build Configuration, change the value from Debug or Release.
Setting the Build Configuration for the Scheme
- Go to the Scheme settings screen from Manage Schemes.
- Select the Build Configuration you created earlier under Build Configuration.
Conditional Branching in Swift
Use code like the following to perform conditional branching.
#if NEWDEBUG
print("NEWDEBUG")
#endif
I have summarized my findings from two and a half years of daily development at home! Please take a look if you'd like.
Discussion