Re: Objects cross calls
Re: Objects cross calls
- Subject: Re: Objects cross calls
- From: Camillo Lugaresi <email@hidden>
- Date: Tue, 24 Jan 2006 14:52:25 +0100
On 23/gen/06, at 19:17, Lorenzo wrote:
My fruit is an object that can contain other fruits in an array called
children, like a hierarchical table.
So when I release a fruit, in the dealloc method I have
- (void)dealloc
{
if(children){
[children release];
children = nil;
}
[super dealloc];
}
Think that now I delete a fruit with
- (void)deleteFruit:(int)index
{
aFruit = [fruits objectAtIndex:index];
[[aFruit basket] removeFruit:aFruit];
[fruits removeObjectAtIndex:index];
}
this cannot work because the fruit within the array fruits could
contain
other fruits which can be retained by other groups. It's
complicated. I
would find a way to disconnect any relationship between groups and
fruits
just when I release the fruit or the group. But I cannot figure out
how.
I don't see what's so complicated about it. When you want to delete a
fruit, you need to remove it from all containers that contain it. You
can either keep a list of containers that contain each fruit, or
search through all containers to find those that contain it. Either
way, when you want to delete a fruit you go through each container
that contains the fruit and remove the fruit from the container (and
the container from the fruit's list of containers, if you choose that
implementation).
You should probably look into Core Data for this kind of application.
I haven't used it yet, but from what I understand it should do much
of the work of managing entities and relationships from you.
Camillo
_______________________________________________
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