title: Unique Instances of NSString for empty or 1-char strings
body: <p>I would like to understand more about the way XCode/Objective-C handle constant strings.  I found a <a href="https://stackoverflow.com/questions/4693665/does-xcode-creates-one-object-for-all-empty-strings">related question</a>, but I would like more information.  Consider the following code:</p>
  
  <pre><code>NSString *a = [[NSString alloc] initWithUTF8String:[[_textFieldA stringValue] UTF8String]];
  NSString *b = [[NSString alloc] initWithUTF8String:[[_textFieldB stringValue] UTF8String]];
  NSString *c = [a copy];
  NSString *d = [a mutableCopy];
  </code></pre>
  
  <p>Note that the textFields are just a way to set the strings at runtime ensuring that the compiler doesn't get too smart on me and build in a single instance.</p>
  
  <p>If my text fields are empty, or contain a single character such as "x" or "$", then a == b == c == the same constant NSString instance.  If I instead provide "xy", then a == c != b.  d is always unique, as one might expect since it is mutable.</p>
  
  <p>Now normally this wouldn't be an issue, I'm not trying to modify the contents of these strings, however, I am working on a system where I frequently use objc_setAssociatedObject.  So here now I might come accross an empty string, and then set associated object data on it, and then have another empty string and collide with the first.</p>
  
  <p>I have, for the moment, solved my issue by creating mutable strings instead.</p>
  
  <p>So my questions:</p>
  
  <ol>
  <li>Is this an Objective-C specification, or an XCode excentricity?</li>
  <li>Does anyone know how the instance is determined?  Why "x" get's one instance, but not "xy"?  I would think some internal dictionary is involved and there's no good reason to stop at 1 character.</li>
  <li>Is there a way to turn this off, so all empty strings are unique instances, or other suggestions?</li>
  </ol>
  
  <p>I am using XCode 5.1.1, OSX 10.9.4, SDK 10.9.</p>
  
  <p>Thank you!</p>