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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:20:43+00:00 2026-05-13T18:20:43+00:00

It is really mind boggling to find out many differences between the iphone and

  • 0

It is really mind boggling to find out many differences between the iphone and the simulators. I spent several hours trying to figure out why my application ran on the simulator but crashed on my iphone device. It turns out the culprit is sortedArrayUsingDescriptors. Are there more get-you like this? Please share with me.

To share with you on the issue and the fixes:


Code crashed on iphone but not simulator

NSSortDescriptor* aDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"count" ascending:NO] autorelease];
NSArray* anNsArray = [[NSArray alloc] init];
NSArray* aSortedNsArray = [[NSArray alloc] init];

aSortedNsArray = [anNsArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:aDescriptor]];

The issue is on [NSArray arrayWithObject:aDescriptor];


The fixes are to create an Array to store it:

NSArray* descriptorArray = [[NSArray alloc] initWithObjects:countDescrp, nil];
aSortedNsArray = [anNsArray sortedArrayUsingDescriptors:descriptorArray];
  • 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-13T18:20:43+00:00Added an answer on May 13, 2026 at 6:20 pm
    NSSortDescriptor* aDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"count" ascending:NO] autorelease]; 
    NSArray* anNsArray = [[NSArray alloc] init];
    NSArray* aSortedNsArray = [[NSArray alloc] init];
    
    aSortedNsArray = [anNsArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:aDescriptor]];
    

    This is a wrong initialization mechanism, and if the code snippet is complete, your problem lies on the anNsArray object that’s empty.

    You also do not need to initialize the aSortedNsArray.

    So it should be:

    NSSortDescriptor* sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"count" ascending:NO] autorelease]; 
    
    // Assume you return it as array of objects from a property or method
    NSArray *array = [self objects]; 
    NSArray *sortedArray = nil;
    if ([array count] > 0) {
         sortedArray = [array sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
    }
    
    // Then you check the sortedArray
    if (sortedArray == nil || [sortedArray count] == 0)
       [self somethingIsWrong];     
    

    arrayWithObject: (autoreleased) or initWithObject: (manual) is just a different way to allocate NSArray object. It won’t cause crashes normally. Because what you care about is the sortedArray not retaining the descriptors array object.

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

Sidebar

Related Questions

This is really twisting my mind… I'm trying to access an NSMutableArray in an
Why does System.Xml.XmlDocument.LoadXml method throw System.Net.WebException ? This is really mind boggling crazy, if
I've recently started develping an application using WPF and I'cant really wrap my mind
This question is coded in pseudo-PHP, but I really don't mind what language I
I have a really dumb question if you don't mind me to ask :(
This is a small doubt and something that shouldn't really come to one's mind.So
Well! I feel really stupid for this question, and I wholly don't mind if
Really simple question - how do I do a search to find all records
Really stuck on trying to write code to unzip a file or directory on
Really stupid question, sorry, but I can't find it on google (I'm sure it's

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.