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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:31:00+00:00 2026-06-05T15:31:00+00:00

I have a problem, storing instances of a viewController object. I want every user

  • 0

I have a problem, storing instances of a viewController object. I want every user to have his/her own screen with some info on it and then be able to do modal to switch user.

The class instance of “User” and the array “Users” are defined in the .h file and the loop runs 5 times – but the array never gets populated:

- (void) chooseNumberOfUsers:(id)sender {
    numberOfUsers = [sender tag];
    NSLog(@"Number of users: %i", numberOfUsers);

    currentUser = 0; // Nul-indekseret

    // Herefter skal vi oprette spillerobjekter
    users = [[NSMutableArray alloc] init];
    for (int i=0; i<numberOfUsers; i++) {
        user = [[UserViewController alloc] init];
        user.userid = i+1;
        [users addObject:user];
    }
    [users addObject:nil]; // Is this necessary?

    // Debug: show info about the first user
    NSLog(@"%@", [users objectAtIndex:0]); }

The user-object are created, but as mentioned, the array “users” never gets populated.

When it has run 5 times, it throws this error:

Terminating app due to uncaught exception
‘NSInvalidArgumentException’, reason: ‘* -[__NSArrayM
insertObject:atIndex:]: object cannot be nil’

  • 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-05T15:31:02+00:00Added an answer on June 5, 2026 at 3:31 pm

    The following line is causing the error

    [users addObject:nil]; // Is this necessary?
    

    As the exception states, you can’t add nil to a NSArray. If you ever need to add a null value to a Cocoa collection, NSNull is the way to do it.

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

Sidebar

Related Questions

I have a precision problem storing a float value in mysql via jpa (EclipseLink).
I'm having a problem relating to storing a variable within Javascript. I have a
I am using LaTeX and I have a problem concerning string manipulation. I want
Hello I have a problem with trimming string in c++. It adds some weird
I have some problem to get the utf-8 string from PHP using jQuery $.load()
I have a problem where I'm having to instantiate instances of objects earlier than
Problem : I have multiple instances of the same C# application running on different
Going deeper in C#, I have encountered a little (strange) problem with object reference
I have an application that creates hundreds of instances of some objects B and
I have a problem in mySQL that goes as follows: Count the instances of

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.