title: What's the idiomatic way of setting an environment variable in Objective C (Cocoa)
body: <p>I <a href="https://stackoverflow.com/questions/11550300/how-can-i-read-a-environmental-variable-in-cocoa">found</a> the idiomatic answer for <em>getting</em> an environment variable, which I might generalize as:</p>
  
  <pre><code>NSString *key = @"&lt;whatever&gt;";
  NSString *result;
  result = [[[NSProcessInfo processInfo]environment]objectForKey:key];
  </code></pre>
  
  <p>But what's the idiomatic way for <em>setting</em> an environment variable?  I see from the <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSProcessInfo_Class/#//apple_ref/occ/instp/NSProcessInfo/environment" rel="nofollow noreferrer">docs</a> that the <code>environment</code> dictionary is a read-only <code>NSDictionary</code> object, rather than an <code>NSMutableDictionary</code>, or some other special class that would allow me to do a <code>setObject:forKey:</code>.  (And indeed, if I coerce the types this way, it has no visible effect.)</p>
  
  <p>I could use the standard UNIX (*nix) way:</p>
  
  <pre><code>char *key = "&lt;whatever&gt;", *value = "&lt;something&gt;";
  int overwrite = 1;
  setenv(key, value, overwrite);
  </code></pre>
  
  <p>And if that's what I need to do, that's what I'll do.  I'm just wondering, is there an idiomatic objective-C way of doing this, that's different, and that I'm just failing to find?  I like to do things in recommended ways where I can, which seems to me it would mean using an Objective-C class... if there is one for doing this.  How do others do this?</p>
  
  <p>(For what it's worth, my next step will be to then execute a program with the modified environment.)</p>