I'm writing some code using Swift 3.0 in Xcode that involves a login page. I'd like to set an environment variable named CurrentUser. Is there a way to define the environment var in the scheme and set the value of the variable programmatically once I log in?
Yes, you can set environment variables programmatically for the current process (which will also be inherited by child processes, by default). You can call the setenv()
function to do it.
This will affect the dictionary returned by future queries of the environment
property of NSProcessInfo
. You can, of course, also retrieve values using the getenv()
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With