Sorting arrays

Hi all,

Could anyone help me translate the following code into ASOC. I tried to get it working but I had no luck.

Hereis the code from a website.

NSMutableArray *myColors = [NSMutableArray arrayWithObjects: @“red”, @“green”, @“blue”, @“yellow”, nil];

NSArray *sortedArray;

sortedArray = [myColors sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]

Thanks in advance.
t.

Hi,


set myColors to current application's class "NSMutableArray"'s arrayWithObjects_("red", "green", "blue", "yellow", missing value)
set sortedArray to myColors's sortedArrayUsingSelector_("localizedCaseInsensitiveCompare:")


Hi Stefan,

Thank you for the answer. I have another question in that what if I want to represent the colors as a variable like shown below. I am not getting a sorted results. Could you help please.

set myColors to {“red”, “green”, “blue”, “yellow”}

set theArray to current application’s class “NSMutableArray”'s arrayWithObjects_(myColors, missing value)
set sortedArray to theArray’s sortedArrayUsingSelector_(“localizedCaseInsensitiveCompare:”)

log sortedArray

use this instead


set myColors to {"red", "green", "blue", "yellow"}
set theArray to current application's class "NSMutableArray"'s arrayWithArray_(myColors)
set sortedArray to theArray's sortedArrayUsingSelector_("localizedCaseInsensitiveCompare:")
log sortedArray

Thank you Stefan. The NSArray *sortedArray; refers to a variable I suppose. The colon confessed me.

Sincerely,
t.

the type of the parameter of sortedArrayUsingSelector is a selector (a method), the colon indicates that the method takes one parameter.
The ObjC method is


- (NSComparisonResult)localizedCaseInsensitiveCompare:(NSString *)aString