title: iOS - NSUserDefaults value returns null for 'valueForKey' but isn't null
body: <p>I am trying to see if a user has made a purchase by retrieving the NSUserDefaults value for each product identifier.
  I save the value when a product is purchased and it is getting set correctly. </p>
  
  <p><strong>The key-value pair show up correctly when calling this:</strong></p>
  
  <pre><code>NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
  </code></pre>
  
  <p><strong>As this:</strong></p>
  
  <pre><code>"com.COMPANY.PRODUCTIDENTIFIER" = 1;
  </code></pre>
  
  <p><strong>But when I try to actually validate that specific key-value it always returns null:</strong></p>
  
  <pre><code>    for (NSString * productIdentifier in _productIdentifiers) {
          NSLog(@"ProductIdentifier: %@",productIdentifier);
          NSLog(@"Defaults Value: %@",[[NSUserDefaults standardUserDefaults] valueForKey:productIdentifier]);
          NSLog(@"Defaults Bool: %d",[[NSUserDefaults standardUserDefaults] boolForKey:productIdentifier]);
          NSLog(@"Defaults Object: %@",[[NSUserDefaults standardUserDefaults] objectForKey:productIdentifier]);
          BOOL productPurchased = [[NSUserDefaults standardUserDefaults] boolForKey:productIdentifier];
          if (productPurchased) {
              [_purchasedProductIdentifiers addObject:productIdentifier];
              NSLog(@"Previously purchased: %@", productIdentifier);
          } else {
              NSLog(@"Not purchased: %@", productIdentifier);
          }
      }
  </code></pre>
  
  <p><strong>Results in this:</strong></p>
  
  <pre><code>2013-03-10 17:45:13.609 COMPANY[1140:907] ProductIdentifier:  com.COMPANY.PRODUCTIDENTIFIER
  2013-03-10 17:45:13.611 COMPANY[1140:907] Defaults Value: (null)
  2013-03-10 17:45:13.612 COMPANY[1140:907] Defaults Bool: 0
  2013-03-10 17:45:13.611 COMPANY[1140:907] Defaults Object: (null)   
  </code></pre>
  
  <p><em>NOTE - The above methods are both called in the same method in this order, so it isn't a problem with the app not loading the defaults yet or anything like that since the value is correctly shown through the 'dictionaryRepresentation' method.
  Also, Company and Product Identifiers have been replaced for privacy. There are no typos in the real app so that is not the issue.</em></p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Ok so this is interesting. If I use a static string as the key, it returns the correct value. But using the 'productIdentifier' (which is NSString) does not, even though logging the 'productIdentifier' it is the exact same string...
  Any Ideas???</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>    for (NSString *productIdentifier in _productIdentifiers) {
          NSLog(@"ProductIdentifier: %@",productIdentifier);
          NSLog(@"Defaults Value: %@",[[NSUserDefaults standardUserDefaults] valueForKey:productIdentifier]);
          NSLog(@"Defaults Bool: %d",[[NSUserDefaults standardUserDefaults] boolForKey:productIdentifier]);
          NSLog(@"Defaults Object: %@",[[NSUserDefaults standardUserDefaults] objectForKey:productIdentifier]);
          NSLog(@"Static Key: %d",[[NSUserDefaults standardUserDefaults] boolForKey:@"com.COMPANY.PRODUCTIDENTIFIER"]);
          BOOL productPurchased = [[NSUserDefaults standardUserDefaults] boolForKey:productIdentifier];
          if (productPurchased) {
              [_purchasedProductIdentifiers addObject:productIdentifier];
              NSLog(@"Previously purchased: %@", productIdentifier);
          } else {
              NSLog(@"Not purchased: %@", productIdentifier);
          }
      }
  </code></pre>
  
  <p><strong>Result:</strong></p>
  
  <pre><code>2013-03-10 17:45:13.609 COMPANY[1140:907] ProductIdentifier:  com.COMPANY.PRODUCTIDENTIFIER
  2013-03-10 17:45:13.611 COMPANY[1140:907] Defaults Value: (null)
  2013-03-10 17:45:13.612 COMPANY[1140:907] Defaults Bool: 0
  2013-03-10 17:45:13.611 COMPANY[1140:907] Defaults Object: (null)   
  2013-03-10 17:45:13.611 COMPANY[1140:907] Static Key: 1   
  </code></pre>