1

I have NSMutableArray named "allConversations" that contains a custom class "Users". every user have property "lastMessageDate".

e.x : user.lastMessageDate;

what is the best way to sort the array by date?

I have this code :

  NSMutableArray *arrCopy = [[NSMutableArray alloc]initWithArray:unSortedArr];
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastMessageDate" ascending:TRUE];
    [arrCopy sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];

but I don't know how to implement it in this situation

2
  • 1
    What happens when you you use lastMessageDate instead of createdAt? Commented Nov 24, 2014 at 13:56
  • My mistake, the "createdAt" is the "lastMessageDate". I changed it now Commented Nov 24, 2014 at 14:02

1 Answer 1

1

it seems all you are missing is the assignment. This should work for you.

arrCopy = [arrCopy sortedArrayUsingDescriptors:@[[[NSSortDescriptor alloc] initWithKey:@"createdAt" ascending:YES]]];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.