Re: retain variables between classes
Re: retain variables between classes
- Subject: Re: retain variables between classes
- From: Lawrence Meeran <email@hidden>
- Date: Tue, 16 Dec 2003 19:36:04 +0000
hello
i'm no expert but i know the answer to this one...
unless you're trying to do something clever, the 'canonical' way of
doing it is like this:
- (void) setInfo: (NSMutableArray*) inArray
{
NSArray* a = array;
array = [inArray retain];
[a release];
}
which will make array *exactly the SAME object* you passed in - ie not
an independent copy.
actually i've seen people on this list saying you can just do this:
- (void) setInfo: (NSMutableArray*) inArray
{
[array release];
array = [inArray retain];
}
but i'm not sure if this is 'safe' -- if it isn't, i'd like to know why
not.
if you want a copy, i would GUESS you do:
...
array = [[inArray mutableCopy] retain];
...
so i think all you're doing wrong, really, is not retaining the object.
hope that helps
L
On Tuesday, December 16, 2003, at 05:54 PM, Jay Rimalrick wrote:
I have two classes MainClass and AClass
AClass has a method (with data item array)
-(void)setInfo: (NSMutableArray *)inArray
{
[array release];
[inArray retain];
array = inArray; // also tried array = [inArray
mutableCopy]
}
MainClass has an AClass defined and calls this method passing in a
mutable
array and when i debug everything is copied fine. However when later
methods and delegates are called of AClass the array it the old one
that was
defined in the initial init call. I checked init and it is only being
called once so
I am assuming that in the setInfo function I am only copying it for
the duration
of the method .... how can I get it to last more than the duration of
the setInfo
method?
any ideas are greatly appreciated
-j
________________________________________________________________
Sent via the WebMail system at 1st.net
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.