title: Comparing NSArray values with NSMutableDictionary
body: <p>I have an <code>NSMutableDictionary</code> which was created from a JSON string.</p>
  
  <p>The problem is that I need to do some pretty complex data comparisons between a <code>NSArray</code> and a <code>NSMutableDictionary</code>. I cannot figure out an efficient way to do so.</p>
  
  <p>The dictionary looks like this:</p>
  
  <p><code>dictionaryMain</code></p>
  
  <pre><code>0 = {
      key1 = value1;
      key2 = value2;
      key3 = {
          subKey1 = {
              subSubKey1 = {
                  inner1 = apples;
                  inner2 = oranges;
              };
              subSubKey2 = {
                  inner1 = grapes;
                  inner2 = lemons;
              };
              subSubKey3 = {
                  inner1 = mangoes;
                  inner2 = kiwis;
              };
          };
      };
      key4 = {
          subKey1 = {
              subSubKey1 = {
                  inner1 = pineapples;
                  inner2 = apples;
              };
              subSubKey2 = {
                  inner1 = oranges;
                  inner2 = mangoes;
              };
          };
      };
  };
  
  1 = {
      key1 = value1;
      key2 = value2;
      key3 = {
          subKey1 = {
              subSubKey1 = {
                  inner1 = watermelon;
                  inner2 = grapes;
              };
              subSubKey7 = {
                  inner1 = bananas;
                  inner2 = oranges;
              };
          };
      };
      key4 = {
          subKey1 = {
              subSubKey5 = {
                  inner1 = kiwis;
                  inner2 = mangoes;
              };
          };
      };
  };
  
  // ... and so on
  </code></pre>
  
  <p>I have an array <code>arrayOfKeys</code> which has some of the <code>subSubKey</code>s as follows:</p>
  
  <p><code>arrayOfKeys</code></p>
  
  <pre><code>{
      subSubKey5,
      subSubKey7,
      subSubKey10
  }
  </code></pre>
  
  <p>I need to loop through my <code>NSMutableDictionary</code> and select only those objects that have the same keys as defined by <code>arrayOfKeys</code>. These selected objects will be added to a new dictionary.</p>
  
  <p>For example, if <code>arrayOfKeys</code> contains <code>subSubKey7</code>, then the <em>object [1]</em> will be selected from the <code>NSMutableDictionary</code> since a key deep inside it has the name <code>subSubKey7</code>.</p>
  
  <p>I tried to figure out a simple way to do this but I couldn't come up with a viable solution. The only thing that I can think of doing is using a lot of nested loops and dirty quick code.</p>
  
  <p>I spent two days trying to figure this out. Any solution for this problem, guys?</p>
  
  <p>Thanks!</p>