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 6715093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:34:23+00:00 2026-05-26T08:34:23+00:00

I have a NSMutableArray consisting out of NSString s. When I need to sort

  • 0

I have a NSMutableArray consisting out of NSStrings. When I need to sort it, I use [array sortUsingSelector:@selector(caseInsensitiveCompare:)] which works perfect.

But sometimes I need to sort the array by substrings of NSStrings. The substring is defined in this case as part of NSString following some marker. The thing is complicated further by the fact that marker can be positioned differently in every string.

Obviously I can break NSString into 2 objects and do sorting on them but it will require significant changes.

Is there a way to do the sorting using selector similar to what I have described above?

I think if not, then I might sort by creating a sorted copy of an array (instead of using selector to do it in place), then releasing the original.

  • 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-05-26T08:34:24+00:00Added an answer on May 26, 2026 at 8:34 am

    You can perform any arbitrarily complex sorting inline with NSMutableArray’s sortWithOptions:usingComparator:

    [myMutableArray sortWithOptions:NSSortStable usingComparator:^NSComparisonResult(NSString* str1, NSString* str2) {
    
        // Scan for your marker in both strings and split on it...
        // Say you store the results in substr1 and substr2...
        return [substr1 caseInsensitiveCompare:substr2];
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a NSMutableArray which contains a few NSString objects. How can I test
I have an NSMutableArray called myObjectArray which contains and array of NSObjects called myObject.
I have an NSMutableArray of NSStrings , which I want to write to a
I have an NSMutableArray called *favorites . It is an array of NSStrings and
I have a NSMutableArray with NSStrings and I want to sort them in alphabetical
I have An NSMutableArray of NSMutableDictionary Which Looks like this Object 1 of Array
I have a NSMutableArray consisting of several elements. From this array I want to
I have an NSMutableArray which holds the dates in format dd/MM/yyyy of type NSString.
I have a NSMutableArray that I need to search for a string and return
I have an NSMutableArray. It's members eventually become members of an array instance in

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.