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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:32:49+00:00 2026-05-13T22:32:49+00:00

In my program I have two classes: Collector and Entity. Collector stores Entities in

  • 0

In my program I have two classes: Collector and Entity. Collector stores Entities in NSMutableArray.

@interface Entity : NSObject {
    ...
}

@interface Collector : NSObject {
    NSMutableArray *entities;
    uint someInt;
    ...
}
- (void)addEntity:(Entity*)newEntity;   // implemented as [entities addObject:newEntity];

Collectors are also stored in NSMutableArray (let’s call it collectors). Then I have such code (something like this):

for (uint i = 0; i < [collectors count]; i++) {
    Collector *curCollector = [[collectors objectAtIndex:i] retain];

    Entity *curEntity = [[Entity alloc] init];
    [curCollector addEntity:curEntity];
    [curCollector setSomeInt:50];

    [curEntity release];
    [curCollector release];
}

After execution of this code part, I have no new entities inside collectors, but someInt value changes correctly. Moreover, when I debug my code, on step before releasing of variables, curCollector contains new entity and has address, same as one of objects inside collectors array, but that object (in collectors array) has no entities.

What am I doing wrong?

P.S.:
During debug I checked all objects – no nils found (especially for entities).
About addObject – all implementation code is [entities addObject:newEntity];
And another interesting thing (to point in in my explanation above) – int value is set correctly (objects of the collectors’ array contain someInt == 50).

P.P.S:
I’ve added a line before releasing code parts:

[collectors replaceObjectAtIndex:i withObject:curCollector];

No results!!

  • 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-13T22:32:49+00:00Added an answer on May 13, 2026 at 10:32 pm

    Hmm. I’m so sorry for wasting your time… There is no errors in this code.
    This code (of course) was a part of the program. And the error was found some steps later.
    The problems during debug process were provoked by XCode debugger, which can’t look deeply in class’s contents. I mean that entity was in entities array. That array was inside collector and this collector was inside collectors array itself. And when I tried to get entities array to some local variable, returned array had entities (displayed in XCode debugger).

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

Sidebar

Related Questions

I have a strange Hibernate behaviour in my program. I have two classes with
I have two classes, a Teacher class and a Student class. In my program
I have a program that compares two classes in a series of tests. The
In a C++ program I have two classes (structs) like struct A { int
In my program I have two classes, one called GlassPiece, and one called TrackerChip.
here is my problem with a Java program: I have two classes (let's call
Hi I have a program where there are two domain classes. One that has
I have two classes. one to run the program and the other for being
I've got a table recording views of programs. Each program can have two different
I have my program that can draw rectangles. I have two problems I can't

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.