Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 16, 2008, 02:46 AM   #1
aztec31
macrumors newbie
 
Join Date: Sep 2008
Sorting NSMutableArray of NSNumber objects

How would I sort a small NSMutableArray that has NSNumber objects. I want to arrange the array in ascending order so the smaller numbers are at the beginning of the array. I looked at the docs but there isn't much examples that are clear. Can someone provide an example?
aztec31 is offline   0 Reply With Quote
Old Sep 16, 2008, 03:06 AM   #2
aztec31
Thread Starter
macrumors newbie
 
Join Date: Sep 2008
I kind of figured it out. I used
[myArray sortUsingSelector: @selector(compare];

but could someone explains what @selector means or does?

By the way this is not for a homework assignment.
aztec31 is offline   0 Reply With Quote
Old Sep 16, 2008, 03:11 AM   #3
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
@selector gets a reference to the function/method that will be called to implement that selector name.
robbieduncan is offline   0 Reply With Quote
Old Sep 16, 2008, 10:11 AM   #4
Fontano
macrumors member
 
Join Date: Jun 2008
Assuming myArray is of type NSMutableArray

Code:
NSSortDescriptor *mySorter = [[NSSortDescriptor alloc] initWithKey:@"property_or_method_of_objects" ascending:YES];
[myArray sortUsingDescriptors:[NSArray arrayWithObject:mySorter];
So take a look at the API documents for NSSortDescriptor for adjustments you may need for your specific case.
Fontano is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
added objects to nsmutablearray, yet the array is null johnmerlino Mac Programming 4 Nov 11, 2011 10:50 PM
Trying to convert object to NSMutableArray johnmerlino iPhone/iPad Programming 4 Nov 11, 2011 03:08 AM
Regenerating NSFetchedResultsController to dynamically change sort descriptor of UITa bicbac iPhone/iPad Programming 0 Nov 4, 2010 03:55 AM
NSMutableArray of UIButton objects XcodeNewb iPhone/iPad Programming 3 Jul 29, 2009 11:20 PM
Storing NSMutableArray full of custom object into NSUserDefaults playboy16 iPhone/iPad Programming 6 Jun 29, 2009 12:00 PM


All times are GMT -5. The time now is 01:57 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC