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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:41:49+00:00 2026-05-30T10:41:49+00:00

I have a subclass of UIViewController with an NSMutableArray as a property to use

  • 0

I have a subclass of UIViewController with an NSMutableArray as a property to use as the data source for a UITableView. I create an instance of the class in my storyboard.

I want to populate the array with the addObject: method but if I try, the array always returns (null).

I read that @synthesize doesn’t init the array and I might need to override -init and init the NSMutableArray there but -init never gets called.

How is this supposed to work?

  • 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-30T10:41:50+00:00Added an answer on May 30, 2026 at 10:41 am

    You need to create an instance of NSMutableArray and assign it to the property.

    Since the object with the property is a UIViewController created in a storyboard, you can do it in a few different places. You can override initWithCoder:, or awakeFromNib, or viewDidLoad.

    If you override initWithCoder:, it is imperative that you call the super method.

    If you do it in viewDidLoad, the array won’t be created until the view is loaded, which doesn’t have to happen right away.

    I recommend doing it in awakeFromNib:

    @synthesize myArray = _myArray;
    
    - (void)awakeFromNib {
        _myArray = [[NSMutableArray alloc] init];
    }
    

    Another option is to just create the array lazily by overriding the getter method of the property:

    @synthesize myArray = _myArray;
    
    - (NSMutableArray *)myArray {
        if (!_myArray)
            _myArray = [[NSMutableArray alloc] init];
        return _myArray;
    }
    

    If you do this, it is very important that you always access the array using the getter method (self.myArray or [self myArray]) and never by accessing the instance variable (_myArray) directly.

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

Sidebar

Related Questions

I have MyViewController class which is subclass of UIViewController. I want to draw filled
I have a UIViewController subclass which has the view property set to a UIScrollView
I have a UIViewController subclass called TripViewController. This class has the following method: -
I have a UIViewController subclass to control a UIView that I want to add
in app i have custom tableview(UITableView *tableView) which subclass of uiviewcontroller & in tableview
In my UIViewController subclass, I have 3 UIView 's with each a @property as
I have a custom UIViewController subclass and I want to override the loadView method.
I have a UIViewController subclass that I am trying to have handle the shake
I have written a subclass of UIViewController which creates a view programmatically, instead of
I have a custom UIViewController subclass, which gets pushed on a UINavigationController stack. I

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.