title: Obj-c - Sort dictionaries in array by date/time?
body: <p>I'm trying to put the people (dictionaries) in my array in order by the date/time located in scheduleddate. Here's the code i'm using, but it doesn't seem to work. The people are simply returned in the same order (and not re-ordered by date/time).</p>
  <p>My current code:</p>
  <p><strong>ViewController.m</strong></p>
  <pre><code>NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
      [dateFormatter setDateFormat:@&quot;MMM dd, yyyy hh:mm&quot;];
  
      self.sortedByTime = [self.dailySchedule sortedArrayUsingComparator:^NSComparisonResult(NSDictionary *obj1, NSDictionary *obj2)
      {
          NSDate *date1 = [dateFormatter dateFromString:obj1[@&quot;scheduleddate&quot;]];
          NSDate *date2 = [dateFormatter dateFromString:obj2[@&quot;scheduleddate&quot;]];
          return [date1 compare:date2];
      }];
      NSLog(@&quot;Sorted Array : %@&quot;, self.sortedByTime);
      }
  </code></pre>
  <p><strong>Contained in my array, I have:</strong></p>
  <pre><code>{
          &quot;first name&quot; = Michael;
          &quot;last name&quot; = Levy;
          scheduleddate = &quot;Feb 14, 2021 05:00 PM&quot;;
        
      },
          {
  
          &quot;first name&quot; = Cali;
          &quot;last name&quot; = Wright;
          scheduleddate = &quot;Feb 14, 2021 10:00 AM&quot;;
    
      },
          {
           &quot;first name&quot; = Janine;
          &quot;last name&quot; = Lohr;
           scheduleddate = &quot;Feb 14, 2021 01:00 PM&quot;;
     
      }
  </code></pre>
  <p><strong>What I want to achieve:</strong></p>
  <pre><code> {
              &quot;first name&quot; = Cali;
              &quot;last name&quot; = Wright;
              scheduleddate = &quot;Feb 14, 2021 10:00 AM&quot;;
        
          },
   {
               &quot;first name&quot; = Janine;
              &quot;last name&quot; = Lohr;
               scheduleddate = &quot;Feb 14, 2021 01:00 PM&quot;;
         
          },
  
   {
              &quot;first name&quot; = Michael;
              &quot;last name&quot; = Levy;
              scheduleddate = &quot;Feb 14, 2021 05:00 PM&quot;;
            
          }
  </code></pre>