MYSTERY ZILLION တွင် English သို့မဟုတ် Unicode ဖြင့်သာ အသုံးပြုခွင့်ရှိသည်။ ဇော်ဂျီ ၊ ဧရာ စသည်တို့ကို အသုံးပြုခွင့် မရှိ။ Unicode fonts များမှာ Mon3,Yunghkio, Myanamr3 စသည်များ အသုံးပြုနိုင်သည်။ Unicode Guide ကို ဒီမှာ Download ချပါ။ Zawgyi to Unicode Converter
Don't share ebook or software if nobody request. You can find free book websites on here. We are welcome for discussion or asking question instead.

How to sorting by CreatedDate file from Document Directory in iOS?

edited June 2013 in iOS Devlopment
Hello everyone.
Now i am trying to sort my NSMutableArray data by CreationDate.

First i explain what i am doing.
1. I retrieved all file lists from document directory with following codes.
<pre lang="cpp">
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSError * error;

self.array = (NSMutableArray *)[[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];
2. I got all files lists and i can show them in UITableView with following codes.
<pre lang="cpp">
cell.textLabel.text = [NSString stringWithFormat:@"%@",[self.array objectAtIndex:indexPath.row lastPathComponent] stringByDeletingPathExtension];
3. It's showing files lists with Ascending Order.

I need to show it by CreationDate.
How can i do that?

Thanks for any suggestions and help.


  • Administrators
    You can use like following

    <pre lang="objc">
    NSString* path = [self.array objectAtIndex:indexPath.row];
    NSDictionary* fileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
    NSDate *result = [fileAttribs fileCreationDate]; //or fileModificationDate
  • edited June 2013 Registered Users
    Hi bro. It's only showing NULL. Please help.

    According to my problem. I want to sorting data by CreationDate that stored in NSMutableArray (self.array) and want to show it in UITableViewCell bro.
  • Administrators
    NULL ? it's NSDate object and you should create NSDateformatter.

    <pre lang="objc">
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSFileManager *manager = [NSFileManager defaultManager];
    NSArray *files = [manager contentsOfDirectoryAtURL:[NSURL fileURLWithPath:documentsDirectory]
    includingPropertiesForKeys:[NSArray arrayWithObject:NSURLContentModificationDateKey]


    NSArray *sortedContent = [files sortedArrayUsingComparator:
    ^(NSURL *file1, NSURL *file2)
    // compare
    NSDate *file1Date;
    [file1 getResourceValue:&file1Date forKey:NSURLContentModificationDateKey error:nil];

    NSDate *file2Date;
    [file2 getResourceValue:&file2Date forKey:NSURLContentModificationDateKey error:nil];

    // Ascending:
    return [file1Date compare: file2Date];
    // Descending:
    //return [file2Date compare: file1Date];

Sign In or Register to comment.