I created a simple environment variable for testing as you can see here:
When I access this env variable in viewDidLoad()
, it's accessible on the app's initial build, but when I close out of the app on both my actual iPhone and simulator, then re-open the app, the app crashes and I can't do anything.
Here is the simple code causing the crash on re-open:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print(ProcessInfo.processInfo.environment["TEST"]!)
}
}
I realize unwrapping the optional is what's causing the crash, but why isn't the environment variable accessible after app close?