title: How to Read String from NSUserDefaults
body: <p>I have an object at the root of plist that stores objects and keys (one of which is input from a user textfield). I have no problem writing and creating structure; it's trying to read values that causing problem. Below code I used to write the data, can someone tell me how to read the string [val] and [myKey]? </p>
  
  <p>thank you!</p>
  
  <pre><code>#define defaultValue @"Your Name"
  #define myKey @"PersonName"
  
  - (void)textFieldAction:(id)sender {
  
      NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
      NSString *val;
  
      // Get the new value from the textfield
  
      val = [myTextField stringValue];
  
      if ([val isEqualToString:defaultValue]) {
          [defaults removeObjectForKey:myKey];
      } else {
          // [defaults setObject:val forKey:myKey];
  
      NSDictionary *my_dict = [NSDictionary dictionaryWithObjectsAndKeys:
                               @"Name", @"PersonName",
                               @"Email", @"PersonEmail", 
                               @"Dept", @"PersonDept", 
                               @"Job", @"PersonJob", 
                               val, myKey, 
                               @"Status", @"PersonStatus", 
                               nil];
  
      [defaults setObject: my_dict forKey: @"Person"];
  
      [[NSUserDefaults standardUserDefaults] registerDefaults:my_dict];
  </code></pre>
  
  <hr>
  
  <p>I would like to automatically populate the textfield with the [val], for [myKey], if the user has the info already in the plist. Here's the code I'm trying to use for that:</p>
  
  <pre><code>- (void)applicationDidFinishLaunching:(NSNotification *)notification {
  
      NSUserDefaults *defaults = [[NSUserDefaults standardUserDefaults] objectForKey:myKey];
      NSString *val = [defaults stringForKey:myKey];
  
      if (val == nil) val = defaultValue;
      [myTextField setStringValue:val];
  </code></pre>