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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:50:35+00:00 2026-05-25T12:50:35+00:00

I have two different NSArray objects, lets say – NSArray* a and NSArray* b

  • 0

I have two different NSArray objects, lets say –

NSArray* a and NSArray* b

Array b is used to store textual content from csv file.

Now. if I do an operation like the following:

a = b;

Am I copying the content of b to a or am I making a point to b? In the former case, changes made to array a won’t be reflected in array b. On the other hand, in the latter case, they will be.

Thanks

  • 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-25T12:50:35+00:00Added an answer on May 25, 2026 at 12:50 pm

    Just a memory address (reference).

    If you are coming from C development, you should know that the star * near the NSArray type means it is a pointer type. This is the same in Objective-C.
    (If you don’t know C and this stuff about pointers, just forget it, as every object type in ObjC is a pointer, it is quite transparent to the final coder)

    If you want to create an independant copy of b, so that modifying a does not modify b then, use the copy method. (If you do, don’t forget to release it later, as any alloc/retain/copy have to be balanced by a release/autorelease call at the end)

    Note anyway that an NSArray is immutable by construct, meaning that there is no method in the NSArray class to modify its content. So for your exact example, pointing to the same NSArray (without making a deep copy) is not really a problem as you can’t modify an NSArray.

    This is starting to become an issue only if you use a NSMutableArray, that do have methods to modify their contents.
    When working with mutable classes like NSMutableArray, you then should use mutableCopy to have a mutable copy (instead of copy which returns an immutable object)

    Let me illustrate this in the following example:

    NSMutableArray* a = [NSMutableArray arrayWithObjects:@"a",@"b",@"c"];
    NSMutableArray* b = a; // points to the same object as a
    NSArray* c = [[a copy] autorelease]; // immutable copy
    NSMutableArray* d = [[a mutableCopy] autorelease]; // mutable copy, independant with a
    
    // Now if you modify a...
    [a addObject:@"d"];
    // ...then b is also modified (it is the same object)
    // but c and d aren't.
    [d addObject:@"independant"];
    // this does only modify d, but neither a, b or c.
    // [c addObject:@"illegal"]; // <-- can't do this, addObject is a method of NSMutableArray, non-existing on NSArray.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different tables from which I need to pull data blogs which
I have two different kinds of objects that I'd like to live under the
My NSArray holds two different types of classes, both of which derive from NSObject
I have two arrays, an NSMutableArray and an NSArray. The NSMutableArray is the store,
I have two different NSDictionary objects where there are keys that belong to both
I have two NSArray s of Movie objects called DVD and VHS. I'd like
I have two different schemas in Oracle (say S1, S2) and two tables in
I have two different ways of displaying items in a WPF application. The first
I have two different grid controls on the same form. They share the same
I have two different-sized monitors, connected together using (I believe) TwinView. I tried System.out.println(Toolkit.getDefaultToolkit().getScreenSize());

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.