0

Im making a IPHONE Phonebook app that has an array of contacts(objects). I am trying to sort this array so it displays the lastName in alphabetical order

But nothing seems to work. I'm not sure where i would put my code in the "MasterViewController". HERE IS PART OF MY CODE

My object looks like the following.

@interface PhoneBookEntry : Person  
@property NSString *firstName;
@property NSString *lastName;
@property NSString *address;
@property NSString *phoneNumber;

@end

@interface MasterViewController : UITableViewController
@property NSMutableArray *elements;
@end

@implementation MasterViewController

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
self.elements = [[NSMutableArray alloc] init];
}

Assume that the array already has elements in it. I need to sort the "self.elements.lastName" array alphabetically PLEASE HELP!!!!!!!!

Mesbah Jamali
  • 73
  • 1
  • 2
  • 5

1 Answers1

0
[self.elements sortUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"lastName" ascending:YES]]];
Eugene
  • 10,006
  • 4
  • 37
  • 55