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 9215951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:18:57+00:00 2026-06-18T02:18:57+00:00

I couldn’t find out why sorting NSArray of DBMetadata (NSObject) doesn’t work. Here is

  • 0

I couldn’t find out why sorting NSArray of DBMetadata (NSObject) doesn’t work. Here is my code. What is wrong? I even tried adding a category to add compare: but it doesn’t work.

- (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata {
    if (metadata.isDirectory) {
        NSLog(@"Folder '%@' contains:", metadata.path);
        for (DBMetadata *file in metadata.contents) {
            NSLog(@"\t%@  is directory? %d", file.filename, file.isDirectory);
            if (file.isDirectory) {
                [self.availableBackups addObject:file];
                DLog(@"llastModifiedDate %@", file.lastModifiedDate);
            }
        }
    }
//    NSLog(@"before sorting: %@", self.availableBackups); //lastModifiedDate //filename

    NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"lastModifiedDate"  ascending:YES selector:@selector(compare:)];
    [self.availableBackups sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];

//    NSLog(@"after sorting: %@", self.availableBackups);
}

self.availableBackups is NSMutableArray

@property (nonatomic, retain) NSMutableArray *availableBackups;

Dropbox – DBMetadata.h

Commented NSLog just print the address of obj, you can see the output of address is still the same after sorting regardless of YES or NO for ascending:

output

2013-01-31 17:20:12.423 Dropbox[7366:c07] before sorting: (
    "<DBMetadata: 0x6bbf010>",
    "<DBMetadata: 0x6bbfb50>",
    "<DBMetadata: 0x6bc1660>",
    "<DBMetadata: 0x6bc17b0>",
    "<DBMetadata: 0x6bc14f0>",
    "<DBMetadata: 0x6bc0dd0>",
    "<DBMetadata: 0x6bc1de0>"
)
2013-01-31 17:20:12.424 Dropbox[7366:c07] after sorting: (
    "<DBMetadata: 0x6bbf010>",
    "<DBMetadata: 0x6bbfb50>",
    "<DBMetadata: 0x6bc1660>",
    "<DBMetadata: 0x6bc17b0>",
    "<DBMetadata: 0x6bc14f0>",
    "<DBMetadata: 0x6bc0dd0>",
    "<DBMetadata: 0x6bc1de0>"
)

with ascending NO

Last Modified file at 0: 2013-01-30 08:00:22 +0000
Last Modified file at 1: 2013-01-30 08:02:54 +0000
Last Modified file at 2: 2013-01-31 09:08:26 +0000
Last Modified file at 3: 2013-01-31 09:14:55 +0000
Last Modified file at 4: 2013-01-31 09:14:08 +0000
Last Modified file at 5: 2013-01-31 09:16:43 +0000
Last Modified file at 6: 2013-01-31 10:36:13 +0000
  • 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-06-18T02:18:58+00:00Added an answer on June 18, 2026 at 2:18 am

    sortedArrayUsingDescriptors: returns an array, it does not modify the array you’re applying it on. If you need to use NSArray, try:

    self.availableBackups = [self.availableBackups sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];    
    

    If you can use NSMutableArray, you could use:

    [self.availableBackups sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];       
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Couldn't find a trace of the source code behind the Photos application that runs
Couldn't figure out how to word the question accurately, so here's an example: Given
I couldn't find the actual function's code as I am interested in how it
Couldn't find this anywhere, maybe I'm looking for the wrong verbs. I'm trying to
Couldn't find anything relevant in forums So ,Please help me with this code .I'm
I couldn't find out python equivalent to PHP $_SERVER. Is there any? Or, what
Couldn't find an answer to this solution, so once I figured it out I
Couldn't find a better way to phrase this question. Here's the deal: I have
Couldn't find any answer to this problem, or not even any questions asked. So
Couldn't find anything in the github documentation and also here on SO. But I

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.