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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:51:23+00:00 2026-05-24T16:51:23+00:00

I’m wondering if it is possible to sort an NSArray of NSStrings based on

  • 0

I’m wondering if it is possible to sort an NSArray of NSStrings based on a number value contained within. Basically its a list of process ID’s and process names, and I would like to sort the processes based on their process ID. The array looks like this :

"286             Google Chrome He",
"1209             ibtool",
"0             kernel_task",
"1             launchd",
"10             kextd",
"11             notifyd",
"12             diskarbitrationd",
"13             configd",
"14             syslogd",
"15             DirectoryService",
"16             distnoted",
"18             ntpd",
"22             SystemStarter",
"25             securityd",
"28             mds",
"29             mDNSResponder",
"30             loginwindow",
"31             KernelEventAgent",
"33             hidd",
"34             fseventsd",
"36             dynamic_pager",
"42             blued",
"43             autofsd",
"46             WDSmartWareD",
"47             WDDMService",
"61             coreservicesd",
"62             WindowServer",
"71             HWPortCfg",
"72             HWNetCfg",
"159             socketfilterfw",
"165             cvmsServ",
"177             coreaudiod",
"191             vmnet-bridge",
"196             vmnet-dhcpd",
"198             vmnet-netifup",
"200             vmnet-dhcpd",
"204             vmnet-natd",
"206             vmnet-netifup",
"220             launchd",
"224             Dock",
"225             SystemUIServer",
"226             Finder",
"228             pboard",
"229             fontd",
"240             UserEventAgent",
"247             AirPort Base Sta",
"252             iprint-listener",
"253             StatusMenu",
"254             Dropbox",
"271             dbfseventsd",
"275             Google Chrome",
"295             Google Chrome He",
"298             AppleSpell",
"634             Google Chrome He",
"696             Google Chrome He",
"730             Microsoft Word",
"733             Microsoft Databa",
"736             Microsoft AU Dae",
"1095             usbmuxd",
"1110             Xcode",
"1171             Interface Builde",
"1282             Interface Builde",
"1283             Interface Builde",
"1475             Google Chrome He",
"1531             Google Chrome He",
"1533             Google Chrome He",
"1681             Google Chrome He",
"1682             Google Chrome He",
"1686             Google Chrome He",
"1687             Google Chrome He",
"1692             Google Chrome He",
"1945             Google Chrome He",
"2088             Keynote",
"2268             Google Chrome He",
"2326             Google Chrome He",
"2481             Google Chrome He",
"2545             Google Chrome He",
"2596             Google Chrome He",
"2766             mdworker",
"2933             Google Chrome He",
"2963             iPhone Simulator",
"2967             SimulatorBridge",
"2970             lsd",
"2971             SpringBoard",
"2982             ocspd",
"2998             installd",
"3000             TableViewControl",
"3001             taskgated",
"3002             gdb-i386-apple-d"

Any help is very much appreciated!

  • 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-24T16:51:25+00:00Added an answer on May 24, 2026 at 4:51 pm

    Yes, you can use the following NSArray instance method:

    - (NSArray *)sortedArrayUsingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context
    

    You’ll need to define an int function that takes three arguments: two array elements to compare, and a context. It returns a NSComparisonResult (-1, 0 or 1). For example:

    NSInteger firstWordIntCompare(id stringLeft, id stringRight, void *context)
    {
        // Extract number from stringLeft and stringRight
        NSArray *wordsLeft = [stringLeft componentsSeparatedByString:@" "];
        NSArray *wordsRight = [stringRight componentsSeparatedByString:@" "];
        NSString *firstWordLeft = wordsLeft.count ? [wordsLeft objectAtIndex:0] : nil;
        NSString *firstWordRight = wordsRight.count ? [wordsRight objectAtIndex:0] : nil;
        int intLeft = [firstWordLeft intValue];
        int intRight = [firstWordRight intValue];
    
        if (intLeft < intRight)
            return NSOrderedAscending;
        else if (intLeft > intRight)
            return NSOrderedDescending;
        else 
            return NSOrderedSame;
    }
    

    Then return the sorted array by calling the NSArray method with your function:

    NSArray *sortedArray = [origArray sortedArrayUsingFunction:firstWordIntCompare context:NULL];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.