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

Similar Threads
thread Thread Starter Forum Replies Last Post
nsmutablearray tacotester1 iPhone/iPad Programming 6 Apr 10, 2014 04:18 PM
OpenGL ES: Vertex Buffer Objects and Vertex Array Objects Blakeasd iPhone/iPad Programming 2 Jul 12, 2013 11:24 PM
Objective-C help with NSMutableArray dancks Mac Programming 4 Apr 15, 2013 04:25 PM
Binding an NSNumber to an NSTableColumn BadWolf13 Mac Programming 4 Dec 30, 2012 03:49 AM
How to select NSNumber data with NSPredicate?? mikezang iPhone/iPad Programming 0 Oct 17, 2012 09:39 AM

Forum Jump

All times are GMT -5. The time now is 03:30 AM.

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

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