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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:12:57+00:00 2026-05-27T08:12:57+00:00

I have a custom NSManagedObject which has several properties. I alloc and init two

  • 0

I have a custom NSManagedObject which has several properties. I alloc and init two instances of the object: compare1 & compare2. Then I do a NSFetchRequest to get two of these custom objects and fill their properties in an NSArray structure to display them in a UITableView later.

My problem is, that the UITableView crashes. I did some research in the code and found out, that sometimes the array does not have the full count. When I play with my sliders and text field it works sometimes, but it is (at least for me) not reproducable.

Thank you in advance!

EDIT: The problem is clear now. The object description is complete. I transfer it to an NSArray via NSArray * array = [[NSArray alloc] initWithObjects: object.value1, ..., nil];. Now the strange thing: [array count] gives me a wrong number? Only the values which are != 0 are in the array. Why so? Thank you!

Here is the code of the NSFetchRequest:

-(NSArray *)performFetch
{

if (__managedObjectContext == nil)
{
    __managedObjectContext = [(MasterViewController *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}

NSError *error = nil;

NSManagedObjectContext *context = [self managedObjectContext];

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Entity" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];

NSLog(@"FetchedObjects Count: %i", [fetchedObjects count]); //always right

compare1 = [fetchedObjects objectAtIndex:0]; //compare is a custom NSObject
compare2 = [fetchedObjects objectAtIndex:1]; //with several properties (.1 to .17)

NSLog(@"%@",[compare1 description]); //is complete
NSLog(@"%@",[compare2 description]); //is complete

NSArray * valuesS1 = [[NSArray alloc] initWithObjects:compare1.1,__andsoon__compare1.14, nil];

NSArray * valuesB1 = [[NSArray alloc] initWithObjects:compare1.14__andsoon__compare1.17, nil];


NSArray * valuesS2 = [[NSArray alloc] initWithObjects:compare2.1,__andsoon__compare2.14, nil];

NSArray * valuesB2 = [[NSArray alloc] initWithObjects:compare2.14__andsoon__compare2.17, nil];


NSMutableArray * valuesArray1 = [[NSMutableArray alloc] initWithObjects:valuesS1, valuesB1, nil];
NSMutableArray * valuesArray2 = [[NSMutableArray alloc] initWithObjects:valuesS2, valuesB2, nil];


compareArray = [[NSMutableArray alloc] initWithObjects:valuesArray1, valuesArray2, nil];

NSLog(@"Array1 count: %i",[values1 count]); //sometimes (I don't know why)
NSLog(@"Array2 count: %i",[values2 count]); //[values1 count] != [values2 count]

return compareArray; //sometimes returns an array with too less objects so my UITableView crashes
  • 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-27T08:12:58+00:00Added an answer on May 27, 2026 at 8:12 am

    Only the values which are != 0 are in the array

    You can’t add nil values directly to an array. (nil is usually zero.) If you need to add “empty” values to an array you need to check and insert an NSNull value instead. For example:

    NSArray * valuesS1 = [[NSArray alloc] initWithObjects:val1 ? val1 : [NSNull null], val2 ? val2 : [NSNull null], nil];
    

    Edit

    The ?: is equivalent to:

    if (val1) {
      return val1;
    }
    else {
      return [NSNull null];
    }
    

    If you want to use @"0" instead of NSNull you can; it can be anything you like as long as it’s an object and is not nil.

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

Sidebar

Related Questions

(sorry about the long title) I have a custom object Person, which in turn
I have custom object MyClass and I need to create 3 instances of it.
Say I have a custom NSManagedObject Department and this has a property representing a
I have custom event that has several different subscribers who will all use the
I have custom coded several enterprise applications for mid to large organizations to use
I have custom js/jquery code which is running fine on all browsers including IE9
I have custom Question objects which I render into html form elements. I want
I have custom CSS for checkbox control into my web form, which is linked
I've noticed that custom NSManagedObject subclass instances do not respond to their accessors when
I have custom type name Netsgroup which is a collection of Net class. Net

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.