سؤال

Yeah there Post of them but none of them working for me , i need to Sort a Multidimentional Array , This is my Array Looks Like

(
{
    FileDate = "2014-02-21T19:08:50Z";
    FileName = "Cyber";
    FileSize = 65;
    FileURL = "Inciden.pdf";
},
    {
    FileDate = "2014-02-21T19:08:47Z";
    FileName = "Products";
    FileSize = 64;
    FileURL = "Plan.pdf";
},
    {
    FileDate = "2014-02-21T19:08:36Z";
    FileName = "Network";
    FileSize = 70;
    FileURL = "cPlan.pdf";
},

)

its the simple NSArray * Fulldata ; Now can anyone tell me a Best Way to Sort it .

هل كانت مفيدة؟

المحلول

I'm assuming you want to sort on date...

NSArray *sortedArray = [FullData sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"FileDate" ascending:NO]];

That should do it.

نصائح أخرى

You posted a dump of an array of dictionaries. There are a number of methods that will let you sort an array in different ways.

I'm partial to the block-based methods like sortedArrayUsingComparator (for immutable arrays) or sortUsingComparator (for sorting mutable arrays in place).

Both of those methods take a comparator block which compares 2 objects from the array and decides which one should be first, returning either NSOrderedDescending or NSOrderedAscending for each comparison.

The system then sorts the array by asking your block of code to compare pairs of objects.

You could also use the methods that uses sort descriptors (e.g. sortedArrayUsingDescriptors:) The descriptor based methods are a better choice if you need to sort using multiple keys (e.g. sort an array of names based on last name, then first name within last name, and then by age within first name.)

In order to help you sort your array we need to know what criteria you want to use to sort it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top