title: Plist Array to NSDictionary
body: <p>I have a plist:</p>
  
  <pre><code>&lt;plist version="1.0"&gt;
    &lt;array&gt;
      &lt;dict&gt;
        &lt;key&gt;name&lt;/key&gt;
        &lt;string&gt;Alabama&lt;/string&gt;
        &lt;key&gt;abreviation&lt;/key&gt;
        &lt;string&gt;AL&lt;/string&gt;
        &lt;key&gt;date&lt;/key&gt;
        &lt;string&gt;1819&lt;/string&gt;
        &lt;key&gt;population&lt;/key&gt;
        &lt;string&gt;4,627,851&lt;/string&gt;
        &lt;key&gt;capital&lt;/key&gt;
        &lt;string&gt;Montgomery&lt;/string&gt;
        &lt;key&gt;largestCity&lt;/key&gt;
        &lt;string&gt;Birmingham&lt;/string&gt;
      &lt;/dict&gt;
      &lt;dict&gt;
        &lt;key&gt;name&lt;/key&gt;
        &lt;string&gt;Alaska&lt;/string&gt;
        &lt;key&gt;abreviation&lt;/key&gt;
        &lt;string&gt;AK&lt;/string&gt;
        &lt;key&gt;date&lt;/key&gt;
        &lt;string&gt;1959&lt;/string&gt;
        &lt;key&gt;population&lt;/key&gt;
        &lt;string&gt;683,478&lt;/string&gt;
        &lt;key&gt;capital&lt;/key&gt;
        &lt;string&gt;Juneau&lt;/string&gt;
        &lt;key&gt;largestCity&lt;/key&gt;
        &lt;string&gt;Anchorage&lt;/string&gt;
      &lt;/dict&gt;
      ...
    &lt;/array&gt;
  &lt;/plist&gt;
  </code></pre>
  
  <p>I am trying to load it into an NSDictionary like this:</p>
  
  <pre><code>NSString *path = [[NSBundle mainBundle] pathForResource:@"stateInfo" ofType:@"plist"];
  
  NSFileManager *fileManager = [NSFileManager defaultManager];
  if ([fileManager fileExistsAtPath:path]) {
      NSLog(@"The file exists");
  } else {
      NSLog(@"The file does not exist");
  }
  
  NSMutableDictionary *myDic = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
  //NSDictionary *myDic = [NSDictionary dictionaryWithContentsOfFile:path];
  NSLog(@"The count: %i", [myDic count]);
  
  NSArray *thisArray = [[NSArray alloc] initWithContentsOfFile:path];
  NSLog(@"The array count: %i", [thisArray count]);
  </code></pre>
  
  <p>I always get an array count of 50 but a dictionary count of zero.  So I tried looping through the array and adding it to the dictionary:</p>
  
  <pre><code>NSDictionary *eachState;
  for (eachState in thisArray) {
      State *thisState = [[State alloc] initWithDictionary:eachState];
      [myDic setObject:thisState forKey:thisState.name];
  }
  </code></pre>
  
  <p>But the loop is throwing an exception:</p>
  
  <blockquote>
    <p><code>*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'</code></p>
  </blockquote>
  
  <p>State is a class with properties matching my plist.  What am I doing wrong?  I see all kinds of related questions out here but I can't get it.</p>