Sorry for asking silly question..
I have an array with class objects like:
Class User {
NSString *firstName, *LastName;
}
@property (nonatomic, retail) NSString *firstName;
@property (nonatomic, retail) NSString *LastName;
I am creating object of this class and adding it in NSMutableArray.
Now I want to sort this array by the first name.. Any idea please.
Can I use NSSortDescriptor for sorting this array or I have to use my custom logic.
I had done this thing earlier but now I forgot this and don't have source code for that right now...
Please help me.. Thanks
EDIT:
I got few kind replies and I tried but not working. I am parsing JSON so there will be unknown number of objects in myArray. So I used :
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES];
[myArray sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
and
NSMutableArray *tempArray = [myArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
but nothing worked..
Edit 2
Here is the description: Array
"<User: 0xa3f13c0>",
"<User: 0xa3f1410>",
"<User: 0xa3f1450>",
"<User: 0xa3f1490>"
Sorted Array
"<User: 0xa3f13c0>",
"<User: 0xa3f1410>",
"<User: 0xa3f1490>",
"<User: 0xa3f1450>"
In for Loop: Array
John
abc
test
qwertg
Sorted Array
John
abc
test
qwertg