Last Updated: 2018-05-27

Quick Look: How to access environment variables and launch options

For in depth information, but not as much reference material, see the Runtime Configuration Guide Apple provides.

For help with understanding where these go and how to use them, consider this excellent article at NSHipster.

Environment Variables:

Misc. Built-in Environment Variables

Variable Value(s) Usage
CFNETWORK_DIAGNOSTICS=3 0,1,2,3 0: Off, 3: Most Verbose - Use with caution, may leak SSL data on your simulator/device
DYLD_PRINT_STATISTICS=1 More options documented here
OS_ACTIVITY_MODE=disable info, debug, disable Sets the logging mode of the launched process to the specified level. See man log for more details.
OBJC_HELP Dumps out a list (during app launch) of other environment variables that vary depending on OS version

Objective-C

NSDictionary* environment = [[NSProcessInfo processInfo] environment];
environment[@"MY_ENV_VAR"];

Swift

let environment = ProcessInfo.processInfo().environment
environment["MY_ENV_VAR"];

Launch Options:

CoreData Options

Launch Option Values Usage
-com.apple.CoreData.SQLDebug 1,2,3 Increasingly verbose log levels for SQL generated by CoreData
-com.apple.CoreData.SyntaxColoredLogging YES, NO Make CoreData logging colorful
-com.apple.CoreData.MigrationDebug YES, NO Enables additional logging for CoreData migrations
-com.apple.CoreData.ConcurrencyDebug 1 1 Enables concurrency checks for NSManagedObject contexts - crash if used on an incorrect thread
-com.apple.CoreData.SQLiteIntegrityCheck 1 Run an SQLite integrity check on initialization

Debugging Localization

Launch Option Values Usage
-AppleLocale Any locale identifier (e.g. 'en', 'it', 'es') Force the locale on app launch
-NSDoubleLocalizedStrings YES, NO Doubles the length of all localized strings, e.g. "Word" => "Word Word" to debug layout issues
-NSShowNonLocalizedStrings YES, NO Shows non-localized strings in ALL CAPS so they're easier to spot
-NSForceRightToLeftWritingDirection YES, NO YES to force right-to-left mode to engage (even in non-RTL languages)

Layout and State Restoration

Launch Option Values Usage
-UIViewLayoutFeedbackLoopDebuggingThreshold number of iterations to consider a loop Enables the Layout Feedback Loop Debugger, and sets the time threshold that triggers it
-UIStateRestorationDebugLogging YES, NO Enables state restoration debug logging for debugging issues with application state restoring
-UIStateRestorationDeveloperMode YES, NO Keeps the state restoration info even if the app crashes

Swift:

# If you want to handle parsing the options on your own:
ProcessInfo.processInfo().arguments // [String]

# The "Arguments" domain in user defaults overrides others, so just grab the value from UserDefaults
UserDefaults.standard

There's more to read!

Did this help solve your problem? If so, consider letting us know on Twitter. You should follow us for all the latest articles and updates:


Have you seen our latest project on Github?.

Sign up for our newsletter

Get an email when new content comes out! Emails are not sold and are used only for announcing updates to the site. Expect ~1-2 emails per month. Unsubscribe any time.