title: How to sort file from document directory by Created Date in iOS?
body: <p>I have a <code>NSMutableArray</code> that retrieved file from document directory in iOS.</p>
  
  <p>i retrieved files from document directory with following codes.</p>
  
  <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0];
      NSError * error;
      self.array = [[NSMutableArray alloc] init];
  
      self.array = (NSMutableArray *)[[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&amp;error];
  </code></pre>
  
  <p>And then i show the lists of file in <code>UITableView</code>.
  However it show with Alphabetically.</p>
  
  <p>I want to show it <strong>sorted by Created Date of file.</strong></p>
  
  <p><strong>Edit</strong></p>
  
  <p>Here is i write in <code>ViewWillAppear</code>.</p>
  
  <pre><code>- (void)viewWillAppear:(BOOL)animated
  {   
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0];
      NSError * error;
      self.array = [[NSMutableArray alloc] init];
  
      self.array = (NSMutableArray *)[[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&amp;error];
  
      [self loadData];  
   }
  
  - (void) loadData
  {
      self.sortedFileList = [self.array mutableCopy];
      [self.sortedFileList sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
          NSDate* d1 = [[NSFileManager defaultManager] attributesOfFileSystemForPath:obj1 error:nil][@"fileCreationDate"];
          NSDate* d2 = [[NSFileManager defaultManager] attributesOfFileSystemForPath:obj2 error:nil][@"fileCreationDate"];
          return [d1 compare:d2];
      }];
  
  }
  </code></pre>
  
  <p>And It not sort by date.</p>
  
  <p>How can i do that?</p>
  
  <p>Thanks for any suggestions and help. </p>