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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:42:37+00:00 2026-05-14T06:42:37+00:00

Totally confused here. I have a PARENT UIViewController that needs to pass an NSMutableArray

  • 0

Totally confused here.

I have a PARENT UIViewController that needs to pass an NSMutableArray to a CHILD UIViewController. I’m expecting it to be passed by reference so that changes made in the CHILD will be reflected in the PARENT and vice-versa. But that is not the case. Both have a property declared as ..

@property (nonatomic, retain) NSMutableArray *photos;

Example:

In PARENT:

self.photos = [[NSMutableArray alloc] init];

ChildViewController *c = [[ChildViewController alloc] init ...];
c.photos = self.photos;
...
...

…

In CHILD:

[self.photos addObject:obj1];
[self.photos addObject:obj2];

NSLog(@"Count:%d", [self.photos count]) // Equals 2 as expected

…

Back in PARENT:

NSLog(@"Count:%d", [self.photos count])  // Equals 0 ... NOT EXPECTED

I thought they’d both be accessing the same memory. Is this not the case? If it isn’t … how do I keep the two NSMutableArrays in sync?

UPDATE with some more code …

IN PARENT UIViewController:

     - (void)loadView { 

         self.photos = [[NSMutableArray alloc] init];

         // Create view for root controller
     UIView *rootView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
     self.view = rootView;
     self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"green_felt_bg.jpg"]];
     [rootView release];

     ChildViewController *c = [[ChildViewController alloc] initWithNibName:@"ChildView" bundle:nil];
     self.childViewController = c;
     [c release];

     self.childViewController.photos = self.photos;
     self.childViewController.delegate = self;

     [self.view insertSubview:self.childViewController.view atIndex:0];
 } 

In the CHILD ViewController I’m just adding objects into it. Calling a delegate method when it is done adding objects … which the PARENT handles. Nothing else significant going on. Code child is using to modify its “photos” property ..

[[self mutableArrayValueForKey:@"photos"] 
        addObject:[photo resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:CGSizeMake(200.0f, 300.0f) interpolationQuality:kCGInterpolationLow]];
  • 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-14T06:42:38+00:00Added an answer on May 14, 2026 at 6:42 am

    You’re right, those property values are pointers, so there should be only one mutable array here. I agree with andyvn22 that something else is going on, something not evident in the code you’ve posted so far.

    Here’s a possible way to debug it: set a breakpoint on each of those NSLogs, and when you drop into the debugger, use the debug window (cmd-shift-Y) to examine the actual memory address of the photos property in each case. There are only two possibilities:

    1. The addresses are the same, in which case it really is the same array, and some code you’re not thinking of is mutating the array between the first log and the second; or,

    2. The addresses are different, i.e. they’re different arrays, and some code you’re not thinking of is reassigning a new array to the child (or parent) photos property.

    Good luck!

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

Sidebar

Ask A Question

Stats

  • Questions 431k
  • Answers 431k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use a caret (^) to escape the % so the… May 15, 2026 at 2:14 pm
  • Editorial Team
    Editorial Team added an answer Two ways: Craft your OAuth URL so it sends them… May 15, 2026 at 2:14 pm
  • Editorial Team
    Editorial Team added an answer You could use the webView:shouldStartLoadWithRequest:navigationType: callback of webview delegate to… May 15, 2026 at 2:14 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.