FakeAccount
FakeAccount

Reputation: 242

NSTask environment variables in swift

How can I set an environment variable for my application in swift? Using the editor schema It works only while running with xcode but not in the compiled application of course.

I already tryed to do:

let environment: NSDictionary = ["launched" : true]
task.environment = environment

but in this way the launcher that I'm going to execute with NSTask will crash (this doesn't happen when I use the editor schema for setting the variable)

Upvotes: 3

Views: 1622

Answers (1)

user4934183
user4934183

Reputation:

Grab the environment dictionary from NSProcessInfo & add your variables to that.

Sounds like the child process needs one of the standard variables like HOME or PATH.

Upvotes: 6

Related Questions