• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Objects cross calls
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Objects cross calls


  • Subject: Objects cross calls
  • From: Lorenzo <email@hidden>
  • Date: Mon, 23 Jan 2006 13:12:03 +0100

Hi,
how should I work with objects referring each other in a cross way?
How to connect an object to the other and have them released properly?
My case: I have a list of fruits.

    NSMutableArray *fruits = [[NSMutableArray array] retain];
    [fruits addObject:orange];
    [fruits addObject:peach];
    [fruits addObject:apple];
    ...

And I have a class MOBasket which contains an array of its own fruits.
The same fruits-objects I have in the fruits array above.

    NSMutableArray *myFruits = [[NSMutableArray array] retain];
    [myFruits addObject:orange];
    [myFruits addObject:peach];
    [myFruits addObject:apple];

So now each fruit has a release count = 2.
This way I can quite tell the basket to change the size of all of its fruits
in one shot.

Now I delete the fruit peach, so I remove it from the fruits array.
    [fruits removeObjectAtIndex:1];
But since it has a retain count = 2 it doesn't get released.
I have to tell the basket to release the object peach too whenever the
object peach has been removed from the fruit lists.
I presume I have to add to the object peach the basket which it is belonging
to, e.g.

     [peach setBasket:basketA];

and when I release the peach object

- dealloc
{
    [basket removeFruit:self];
    [super dealloc];
}

But now if I delete the basketA, how can the peach call its basket?
I suppose that when I relase the basket I have to tell it to release
myFruits array this way

- dealloc
{
    [myFruits release];
    [super dealloc];
}

Sorry for the confusion, it's what I have in my mind actually.
Any help would be welcome.
Using ID numbers cannot really help me because I need the utmost speed when
changing a parameter to all the fruits in a basket, so I would not like to
retrive the fruits of a basket any time I move a slider.


Best Regards
--
Lorenzo
email: email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Objects cross calls
      • From: j o a r <email@hidden>
    • Re: Objects cross calls
      • From: Pontus Ilbring <email@hidden>
  • Prev by Date: NSAttributedString & alert panels?
  • Next by Date: Re: anotherDockProgram-help
  • Previous by thread: Re: NSAttributedString & alert panels?
  • Next by thread: Re: Objects cross calls
  • Index(es):
    • Date
    • Thread