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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:30:35+00:00 2026-06-10T09:30:35+00:00

In the code below, I am trying to add objects to array. No error,

  • 0

In the code below, I am trying to add objects to array. No error, but is not adding objects either. Sorry for asking this pretty basic question. Need help

The NS Object Definition
//DataDefinition.h
#import

@interface DataDefinition : NSObject
@property (nonatomic, retain) NSString *dataHeader;
@property (nonatomic, retain) NSMutableArray *dataDetails;

@end

The DataDefinition Implementation

#import "DataDefinition.h"
@implementation DataDefinition

@synthesize dataHeader;
@synthesize dataDetails;

@end

The Display header section
//DataDisplay.h
#import

#import "DataDefinition.h"

@interface DataDisplay : UITableViewController
@property (strong, nonatomic) NSMutableArray *dataSet;
@property (strong, atomic) DataDefinition *individualData;

@end

The Display implementation section

 //DataDisplay.m
 #import "DataDisplay.h"

 @interface DataDisplay ()
 @end

 @implementation DataDisplay
 @synthesize dataSet;
 @synthesize individualData;

- (void)viewDidLoad
{

    [super viewDidLoad];

    individualData.dataHeader  = @"Header1";
    individualData.dataDetails = [[NSMutableArray alloc] initWithObjects:@"Header1-Detail1", @"Header1-Detail2", @"Header1-Detail3", nil];

    //This didnot add
    [dataSet addObject:individualData];
    NSLog(@"Count of objects is %d:",[dataSet count]);

    //Nor did this
    dataSet = [[NSMutableArray alloc] initWithObjects:individualData, nil];
    NSLog(@"Count of objects is %d:",[dataSet count]);

    self.title = @"DataDisplay";
}
  • 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-10T09:30:36+00:00Added an answer on June 10, 2026 at 9:30 am

    The issue is that individualData is never actually set to an instantiated object (in other words, it is never initialized).

    These kinds of oversights are common due to Objective-C’s non-error policy regarding sending messages to nil; it’s perfectly legal and often useful principle. This means that your code will never complain until you try to pass it to some method which will crash if it sees nil. Unfortunately, you are using initWithObjects, which simply sees nil as the end of the (empty) list. If you had instead tried to use [NSArray arrayWithObject:individualData] you may have seen an error which would hint to you that you had nil instead of an object.

    Note that setting properties on nil is particularly tricky, since it looks like you are simply dealing with a C-syle lvalue, when actually it translates to a message-send call at runtime:

    individualData.dataHeader  = @"Header1"; 
    // is *literally* the same as:
    [individualData setDataHeader:@"Header1"]; 
    

    You can take your pick of solutions. The “cheap” way is to simply initialize it right there. The “better” way (usually) is lazy-instantiation (i.e. in the getter). Since the object is marked as atomic, you likely need to let the compiler write the getter for you, and just initialize it in viewDidLoad (or awakeFromNib, initWithCoder, or similar):

    - (void)viewDidLoad
    {
    
        [super viewDidLoad];
        self.individualData = [[DataDefinition alloc] init];
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a plot (sample code pasted below) that I am trying to add
I am trying to run the code below but it keeps locking up my
I am trying to port the code below to mootools 1.1 code but am
In the below code I am trying to populate the JSON array with JSON
I'm using the javascript code below trying to extract the number after gallery-entry_ in
In the code below i`m trying to read a list of selected projects and
In the code below I am trying to clone a git repository to another
Afternoon all, Using the code below I'm trying to load what is render by
The code below is what I am trying to use in order to get
I am trying to modify the code below to check the input from a

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.