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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:39:59+00:00 2026-05-30T00:39:59+00:00

Say I have NSMutableArray *array1 with 10 objects. I want to create an *array2

  • 0

Say I have NSMutableArray *array1 with 10 objects. I want to create an *array2 and add 5 objects from array1 to array2, and I want it so that when I change these object properties from array2, they also change the 5 specific objects from array1 as well. How would I do this?

Edit: Ok I think I asked the wrong question. It’s more about passing by reference and pointers, which I confuse too much:

NSMutableArray *mainArray;
NSMutableArray *secondaryArray;
NSMutableDictionary *dic1;

[mainArray addObject:dic1];
[self changeValues:[mainArray lastObject]];

-(void)changeValues:(NSMutableDictionary*)someDic
{
    [secondaryArray addObject:someDic];
    NSMutableDictionary *aDic=[secondaryArray lastObject];
    ...//some code to change values of aDic
    //by changing aDic, I want to also change the same dic from mainArray

    //so [mainArray lastObject] should be the same exact thing as [secondaryArray lastObject]
}

How would I change the above code so the changes reflect in both arrays?

  • 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-30T00:40:02+00:00Added an answer on May 30, 2026 at 12:40 am
    NSMutableArray *array2 = [NSMutableArray array];
    for (int i=0; i<5; ++i){
        [array2 addObject: [array1 objectAtIndex:i] ]
    }
    

    In this example you have the set of objects pointed by items of array1 as well as by items
    of array2, since NSMutableArray contains pointers to objects, not objects theirselves.
    Therefore, changing the object thru pointer in one array you may observe that change thru
    pointer from other array.


    Edit

    @mohabitar, you already receive an answers. dic1, someDic and aDic – all these values are same. Just change aDic(or someDic) and see result.

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

Sidebar

Related Questions

Say I have a class Car that has 2 properties: NSMutableArray *parts and BOOL
Say I have a tableview class that lists 100 Foo objects. It has: @property
Say have a linear model LM that I want a qq plot of the
I have a NSMutableArray that I create on program load. If the program terminates,
For example say I have: NSMutableArray *array = [[NSMutableArray alloc] init]; NSMutableArray *array2 =
Let's say have something like: SELECT energy_produced, energy_consumed, timestamp1 AS timestamp FROM ( SELECT
Say I have three files (template_*.txt): template_x.txt template_y.txt template_z.txt I want to copy them
I have a question about Objective-C today involving NSMutableArray. Coming from a .net/c# background
I have an NSArray which contains Person objects. This person object contains the following;
Say you have a method that returns a newly generated NSArray instance that is

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.