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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:20:00+00:00 2026-05-23T17:20:00+00:00

I am having troubling adding nil at the end of an array, I get

  • 0

I am having troubling adding “nil” at the end of an array, I get “NSInvalidArgumentException” ?

NSMutableArray *k = [NSMutableArray arrayWithCapacity:10];

for (int i=0; i<9; i++){
    [k addObject: @"blank"];
}
[k addObject: nil]; //<-- NSInvalidArgumentException

I need to do all this item by item in a loop and then add the “nil”.

Thanks

(I am then taking this array and initializing a 2D array.
The problem is that I can’t successfully “replaceObjectAtIndex” with an array without “nil”.
If I build the “k” with “initWithObjects: @”blank”, @”blank”, @”blank”, … nil” this will work. However writing 1000 blanks is a little much. So that is the purpose of the loop.)

////// HERE IS THE TRIAL AND ERROR CODE for init and building 2D Matrix for the purpose of reading and storing a matrix from a “CSV file” //////

///*
NSMutableArray *ppp = [NSMutableArray arrayWithCapacity:2];
NSMutableArray *kkk = [NSMutableArray arrayWithCapacity:20];

NSNull *myNull = [NSNull null];
for (int i=0; i<9; i++) {
    //[kkk addObject: [NSMutableString stringWithFormat: @"%d",i]];
    [kkk addObject: myNull];
}
//[kkk addObject: nil];

[ppp addObject:kkk];
[ppp addObject:kkk];
//*/


/*
// this is successful --> just uncomment this block and comment out the block above
[ppp addObject:[[NSMutableArray alloc] initWithObjects:
             @"z1",
             @"z2",
             @"z3",
             @"z4",
             @"z5",
             @"z6",
             @"z0gg",
             @"z0hh",
             @"z0ii",
             @"z0jj",
             nil
             ]];

[ppp addObject:[[NSMutableArray alloc] initWithObjects:
        @"a1",
        @"b2",
        @"c3",
        @"d4",
        @"e5",
        @"f6",
        nil
        ]];

*/

[[ppp objectAtIndex:0] replaceObjectAtIndex:1 withObject:@"HOTDOG"];
[[ppp objectAtIndex:1] replaceObjectAtIndex:1 withObject:@"HOHO"];
// HOHO will replace HOTDOG as well for the code not using "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-05-23T17:20:00+00:00Added an answer on May 23, 2026 at 5:20 pm

    You cannot add nil to an NSMutableArray, and you will raise an exception if you try to.

    There’s NSNull, though:

    NSNull *myNull = [NSNull null];
    [myMutableArray addObject:myNull];
    

    You might ask yourself why you’re trying to do this, however.

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

Sidebar

Related Questions

Having the following domain class: class Message{ } Want to get all messages with
I'm having troubling linking a program with sqlite3. Any ideas? gcc -g -O2 main.o
So I've done some looking online and throught the documentation, but I'm having troubling
Having the following code: int main(int argc, char* argv[]) { // program code std::cout
Having some trouble w/ IE7. IE8, Chrome, Firefox all work fine, but IE7 won't
I'm having troubling completing a task the RESTful way. I have a tasks controller,
I am having troubling creating a nested signup form for users that are using
I am having troubling reading my values out of an ArrayList. The compiler goes
Having the following code: #include <iostream> struct A { int x; A(){} ~A(){std::cout <<~A(<<x<<)\n;}
Having a issue where all mobile devices is zoomed 50% in at start. That

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.