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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:58:20+00:00 2026-06-17T06:58:20+00:00

Having a hard time figuring this one out… does addObjectsFromArray, a convenience method inside

  • 0

Having a hard time figuring this one out…

does addObjectsFromArray, a convenience method inside of NSArray copy everything, or does it keep the ‘otherArray’ parameter where it is in memory and do a LinkedList style point the tail to the ‘otherArray’ kind of move?

Im asking because I have pointers to important objects in some existing-array, but these pointers may point to a different object on an incoming-array.

I re-point my important-object-pointer to some object within the incoming-array, and then call addObjectsFromArray on the existing-array with the incoming-array.

My worry is that my re-pointed important-object-pointers will point to nothing if the incoming-array is actually copied, when ARC decides to nil out the incoming-array.

  • 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-17T06:58:21+00:00Added an answer on June 17, 2026 at 6:58 am

    I think you’re overthinking this. You won’t have a pointer “into” an NSArray. You’ll have a pointer to an object, and the NSArray will also have a pointer to that object. Reassigning your pointer will not change the pointer in the NSArray.

    As for copying, NSArray does not copy objects. But as noted above, it does copy the pointer to the object, rather than holding a pointer-to-a-pointer or something weird like that. So in this code:

    NSMutableString *a = [NSMutableString stringWithString:@"Cool"];
    NSMutableString *b = a;
    NSMutableArray *array = [NSMutableArray array];
    [array addObject:a];
    NSMutableString *c = [array objectAtIndex:0];
    [b appendString:@" beans"];
    a = nil;
    

    At the end of running:

    • b and c will be hold same NSMutableString — “Cool beans” — and mutating either of them would show up in the other one

    • The array holds the same NSMutableString as b and c — “Cool beans” — and accessing the string there will also show mutations to the string

    • a will be nil. This didn’t affect any of the other pointers to the string when we reset it, because they point to the string, not the variable.

    When you addObjectsFromArray:, it is just as though you iterated over the array and added each individually. The other array could go away at that point and it wouldn’t matter, because your NSArray now has pointers to all the objects.

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

Sidebar

Related Questions

I'm having a hard time figuring this one out. Seems like no matter what
I am having a hard time figuring this one out,i keep getting an error:
Having a hard time figuring this one out. I have 3 tabs at the
I'm having a hard time figuring this one out, so I ask for your
Having a hard time figuring out why this alert code is being called once
Having a hard time figuring out the best way to do this... I have
I'm having a hard time figuring this problem out - I am trying to
I'm having a hard time figuring out how to association one of my models
Having a really hard time figuring this out. I need to submit a form
I was having a hard time figuring out a good title for this question,

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.