Swift Beginner: How to run code only in development mode
Published in
1 min readOct 22, 2018
Sometimes when we are programming, we wan to run some code only in development mode, for example changing the URL of an API from Development to Production or filling a Login View with a test user and password.
To do this we can use the #if #elseif #else #endif
statements to define a Conditional Compilation Block like is stated in the swift documentation
#if DEBUG
usernameTextField.text = "swift"
passwordTextField.text = "swiftIsAwesome"
#endif
By default this code is removed from a Release
version, you can also define your own flags using Xcode Active Compilation Conditions defined in your Target
Build Settings / Swift Compiler-Custom Flags
Until the next time…