Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8321747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:07:54+00:00 2026-06-08T23:07:54+00:00

I am receiving a weird sort error. I have a list of ranges in

  • 0

I am receiving a weird sort error. I have a list of ranges in an array called wordArrayDuplicates. I need to sort this array based on range location so i convert the string to an NSNumber but it wont compare.

* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSCFString
sortedArrayUsingComparator:]:

  - (NSArray *)sortedArray {
            if (!sortedArray) {
            sortedArray = [[NSArray alloc]init];
             }
        return [wordArrayDuplicates sortedArrayUsingComparator:(NSComparator)^(id obj1, id obj2){
            NSNumber * lastName1 = [NSNumber numberWithInt:NSRangeFromString(obj1).location];
            NSNumber * lastName2 = [NSNumber numberWithInt:NSRangeFromString(obj2).location];
            return [lastName1 compare:lastName2]; }];
    }
    -(void)beginGoingThroughDuplicatesAtWordIndex:{
        if (index == 1) {[self loadDuplicates];}
        [string addAttribute:(id)kCTForegroundColorAttributeName
                       value:(id)[UIColor blackColor].CGColor
                       range:NSMakeRange(0, string.length)];
        BOOL shouldContinue = YES;
        while (shouldContinue == YES && index<[[self sortedArray] count]) {
            if (![[tv.text substringWithRange:NSRangeFromString([[self sortedArray] objectAtIndex:index-1])] isEqualToString:[tv.text substringWithRange:NSRangeFromString([[self sortedArray] objectAtIndex:index])]]) {
                shouldContinue = NO;
            }
                [string addAttribute:(id)kCTForegroundColorAttributeName
                               value:(id)[UIColor redColor].CGColor
                               range:NSRangeFromString([sortedArray objectAtIndex:index-1])];
            index++;
        }
           textlayer.string = string;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:07:56+00:00Added an answer on June 8, 2026 at 11:07 pm

    When you sort the array using sortedArrayUsingSelector:, as in

    [wordArrayDuplicates sortedArrayUsingSelector:@selector(sortedArrayUsingComparator:)];
    

    you are passing the selector which is going to be called on each of the objects in the array. So you must be providing some method that is implemented in the objects that’s in the array. For example, compare:, a standard method for NSString:

    [wordArrayDuplicates sortedArrayUsingSelector:@selector(compare:)];
    

    You are passing another NSArray method. You must choose, either you want to sort using selector or using comparator, but you cannot call one inside of the other.


    In your example in - (NSArray *)sortedArray you are using sortedArrayUsingComparator: correctly, stick to that way.

    Usage recommendation

    In general, one should use sortedArrayUsingComparator: when sorting array from one place of the code, to avoid creating selectors in the object classes.

    When sorting is being called from many places in the code, then creating a selector may be more useful. Even if it isn’t your own object and you’re just sorting NSString in some special way, you can create a category on NSString with some customCompare: method and use it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep receiving this error... [2012-06-14 11:54:50,072: ERROR/MainProcess] Hard time limit (300s) exceeded for
I am receiving a parse error which is this: Parse error: syntax error, unexpected
Why am I receiving this Rake error: $ rake --version /Volumes/Data/sampablokuper/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not
I'm creating a linked list data structure in C. However, I'm receiving some weird
Receiving this error: a different object with the same identifier value was already associated
we have just experienced a weird error on our applications connecting to a clustered
I'm receiving this weird problem when updating the structure of my site. Site URL
I have an extremely weird error that I cannot figure out. float distance =
OK, this problem is very odd. I am receiving a list of items using
I am receiving a weird result in this MySQL query. I am attempting to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.