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

  • Home
  • SEARCH
  • 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 7809379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:25:07+00:00 2026-06-02T03:25:07+00:00

I’m currently trying to teach myself Objective-C and was playing around with an exercise

  • 0

I’m currently trying to teach myself Objective-C and was playing around with an exercise where I needed to sort an array.

I managed to complete it using the following code:

NSSortDescriptor * newSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:TRUE];
NSArray *sortDescriptors = [NSArray arrayWithObject:newSortDescriptor];
[self.theBookStore sortUsingDescriptors:sortDescriptors];

My question is about what is actually happening here. I don’t really understand exactly what I’ve done.

Line 1: I understand here I’ve created a new object that has a descriptor. This has two parameters, the column I want to sort on and that it is ascending.

Line 2: This is the line I’m confused about. Why do I need an array of sort descriptors? When I read this code I suspect it creates an array with only one row is that correct?

Line 3: I understand that this is calling the sortUsingDescriptors method but again, my confusion is why this function expects an array.

I’ve read the documentation but I’m really looking for a simple explanation.

Any help is 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-06-02T03:25:09+00:00Added an answer on June 2, 2026 at 3:25 am
    • Line 1: .. yes your right. You are creating a custom object called NSSortDescriptor. That object defines a attribute to sort after. You did enter “title”. So the objects in your array-to-sort will be sorted after that property (yourObject.title “kind-of”).

    • Line 2: Because the sorting method (sortUsingDescriptors) always needs a array, you need to create a NSArray with only one object. Okay, … looks kind of stupid. But makes absolute sense. Lets say you would like to sort after two criteria (lets say “title”, then “city”).

    • Line 3: Yes heres must be a array because of sorting after more then one criteria.

    And always keep the memory clean:
    On line 1 you did allocate/init a NSSortDescriptor.
    So clean up after using it (if you are not using ARC).
    So add a line:

    [newSortDescriptor release];
    
    • 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
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:

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.