Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

Thread: Sorting NSArray
View Single Post
Old 09-06-2008, 08:31 PM   #4 (permalink)
PhoneyDeveloper
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

Here's how I do it in my Person class:

This line does the sort in the NSMutableArray containing Person objects:

Code:
		[array sortUsingSelector:@selector(compareFullCommaName:)];
This method is implemented in the Person class:

Code:
-(NSComparisonResult)compareFullCommaName:(MPerson*)inPerson
{
	NSString*	selfCommaName = [self textForField:kPersonFullNameComma];
	NSString*	otherPersonCommaName = [inPerson textForField:kPersonFullNameComma];
	
	return [selfCommaName compare:otherPersonCommaName];
}
The full comma names are 'lastname, firstname' but you get the idea. You need a comparison method that returns an appropriate NSComparisonResult. Look at the docs for sortUsingSelector:

BTW, answers to basic Cocoa/Foundation questions like this can be found on Cocoabuilder.com. See for instance http://www.cocoabuilder.com/search/a...rds=sort+array

Last edited by PhoneyDeveloper; 09-06-2008 at 08:33 PM.
PhoneyDeveloper is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,822
Threads: 89,206
Posts: 380,635
Top Poster: BrianSlick (7,129)
Welcome to our newest member, gladlard24
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:28 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.