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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:35:45+00:00 2026-06-12T05:35:45+00:00

I have a method that creates a dictionary from NSJSONSerialization class. I then enumerate

  • 0

I have a method that creates a dictionary from NSJSONSerialization class. I then enumerate the json, and create objects to store state for each instance.

- (void)fetchedData:(NSData *)responseData {

    NSError* error;
    NSDictionary *json = [NSJSONSerialization
                          JSONObjectWithData:responseData
                          options:kNilOptions
                          error:&error];

    NSArray *moviesJson = [json objectForKey:@"movies"];

    for(NSDictionary *element in moviesJson)
    {
         RABMovie *myMovie = [[RABMovie alloc] initWithJson:element];
       // RABMovie *myMovie = [RABMovie new];
       // myMovie.json = element;

        [_myMovieNames addObject: myMovie];
        myMovie = nil;

    }

    [self.movieTableView reloadData]; 
}

Problem: I want to create my object by passing in element in the allocator, however when I do this, my UITTableView rows all contain the same movie data. It is always the last item, leading me to believe I am working with only one memory address, and the last update affects the whole collection.

If I uncomment the code to use the json as a property instead of a alloc param, I no longer have the issue and all works well. I’ve also tried creating a completely new NSDictionary via a deep copy of element to no avail.

Does someone know why this is happening? BTW, I am using ARC. -Thanks for the time.

Edit: Added more code. I’ve included a property movieName to illustrate how I use the ivar _json.

@implementation RABMovie

NSDictionary *_json;
- (id) initWithJson: (NSDictionary*) jsonAsDictionary
{
    if (self = [super init])
    {

        _json =  jsonAsDictionary;
    }

    return self;
}

- (NSString*) movieName
{
    return [_json objectForKey:@"title"];
}
  • 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-12T05:35:47+00:00Added an answer on June 12, 2026 at 5:35 am

    I think you meant to declare _json as an instance variable. Instead it’s a globally visible (at least within that class) variable – not 100% sure on the scoping rules, but regardless, it’s not an instance variable – it’s a single variable shared by all instances! Try this instead:

    @implementation RABMovie {
        NSDictionary *_json;
    }
    
    /* ...rest of class */
    
    @end
    

    Putting it inside the curly braces after the @implementation directive makes it an instance variable. Hope this helps!

    EDIT: Do you have a property called json on RABMovie already? Then you can skip the instance declaration altogether and the compiler will generate the an instance variable for you. That’s probably happening already actually, which is why it works when you go through the property – it’s accessing the ivar rather than the “global”.

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

Sidebar

Related Questions

I want to create a Javascript class/object that allow me to have various method:
I have a dictionary that I read from a plist. I want to create
I have a method that creates a local textfield and pops up the keyboard
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I have a method CreateAccount(...) that I want to unit test. Basically it creates
I have a unit test that creates a mock calls my method to be
I have a class that creates a calendar. One of the methods finds the
I have a winforms application and I am trying to create a method that
Hi I want to create a WCF service that have login method, which is
I have a method in c++ that gets called from python and needs to

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.