Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6686043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:07:35+00:00 2026-05-26T05:07:35+00:00

Huge fan of this website, but it’s my first post! I’ve got an array

  • 0

Huge fan of this website, but it’s my first post!

I’ve got an array of filenames in a directory and I want to sort them. There are hundreds of posts about sorting, but I couldn’t find anything I could use about sorting by modification date.

Here’s my code so far. It successfully creates an array of files that feeds into my tableview. I just need to sort it by modification date, not alphabetically:

//Create dictionary with attributes I care about and a fileList array

        NSMutableArray *fileList  = [[NSMutableArray alloc] initWithCapacity:10];
        NSDictionary *fileData = [NSDictionary dictionaryWithObjectsAndKeys:file, @"file", dateString, @"date", nil];

        [fileList addObject:fileData];

//I don't know how to sort this array by the "date" key!

        NSArray         *files = [fm contentsOfDirectoryAtPath:folderPath error:NULL];
    //iterate through files array
        for (NSString *file in files) {
            NSString *path = [folderPath stringByAppendingPathComponent:file];
    //code to create custom object with contents of file as properties
    //feed object to fileList, which displays it in the tableview

I’ve read everything I could find online about it, but I just don’t understand how this sorting would work. I understand there are about four different ways to sort, but which one do I chose to sort the array by the date key in the dictionary and how would I implement it here?

Thanks!

EDIT:

Found the answer about 5 seconds after posting this. The code I needed was:

NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES];
[sortedFiles sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]];

So stupidly easy, I’ve spent all day on this!

Hope this helps someone!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:07:36+00:00Added an answer on May 26, 2026 at 5:07 am

    Just to clarify, the answer was:

    NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES];
    [sortedFiles sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me start by saying I'm a huge fan of the elegance of this
Lately I have become a huge fan of XSL, XPath and XML, but I've
i want a function that finds some strings i've got in an array in
I am a HUGE LINQ2SQL Fan. But I use a lot of DataContext in
I'm becoming a huge fan of CoffeeKup, but I'm wondering how I can use
I'm a huge fan of Tipfy , but it's no longer being maintained. Webapp2
I'm not a huge fan of tools like Ant, but they are certainly useful.
I am a new, but huge fan, of the BDD approach to software development
I have been a huge fan of Jquery validate since it came out but
I'm a huge fan of robocopy and use it extensively to copy between various

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.