0

I want to sort this array of NSStrings:

"Page_1",
"Page_10",
"Page_11",
"Page_12",
"Page_13",
"Page_14",
"Page_15",
"Page_16",
"Page_17",
"Page_18",
"Page_19",
"Page_2",
"Page_20",
"Page_21",
"Page_22",
"Page_23",
"Page_24",
"Page_3",
"Page_4",
"Page_5",
"Page_6",
"Page_7",
"Page_8",
"Page_9"

but I keep getting an error with this code:

NSArray* sortedArray = [currentViews sortedArrayUsingSelector:@selector(compare:NSNumericSearch)];

Not even sure if this is the correct approach to take, looking at the NSArray docs makes me think I should be going with a comparator. Any help would be appreciated.

2 Answers 2

2

You will indeed need a comparator, as what you are trying to sort is really a NSString, not a NSNumber.

Sign up to request clarification or add additional context in comments.

Comments

-1

You cannot fix an argument within an @selector - @selector(compare:NSNumericSearch) is looking for a method compare:NSNumericSearch and that does not exist!

You can use a comparator to invoke the correct compare method:

NSArray *sortedArray = [currentViews sortedArrayUsingComparator:(NSComparator)^(NSString *a, NSString *b)
                        {
                           return [a compare:b options:NSNumericSearch];
                        }
                       ];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.