---
title: "How do you read environment variables in Swift?"
description: "Read environment variables with ProcessInfo, set them in the Xcode scheme for debugging, and use build settings or xcconfig for values a shipped app needs."
url: "https://bugsee.com/answers/swift/swift-environment-variables/"
---

# How do you read environment variables in Swift?

Read them with `ProcessInfo.processInfo.environment["NAME"]`. For development, set them in the Xcode scheme; a shipped iOS app does not inherit your shell's variables.

```swift
let env = ProcessInfo.processInfo.environment

let home = env["HOME"]                 // String?
let isCI = env["CI"] != nil

if let level = env["LOG_LEVEL"] { print(level) }
```

- In Xcode: Product > Scheme > Edit Scheme > Run > Arguments > Environment Variables adds values for debug runs only.
- On a device outside Xcode, the variables you set in the scheme are not present, so never rely on them in a release build.
- For values that must ship, such as an API base URL per configuration, define them in an .xcconfig file, expose them through Info.plist and read them with Bundle.main.object(forInfoDictionaryKey:).
- Do not ship secrets this way; anything in the app bundle can be extracted.

## Related questions

- [Where is the Info.plist file in a new Xcode project?](https://bugsee.com/answers/swift/where-is-info-plist/)
