Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set environment variables programmatically? [closed]

Tags:

xcode

ios

swift

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?

like image 972
Jonah Elbaz Avatar asked Oct 19 '17 02:10

Jonah Elbaz


1 Answers

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.

like image 67
Ken Thomases Avatar answered Sep 20 '22 00:09

Ken Thomases