Re: retain variables between classes
Re: retain variables between classes
- Subject: Re: retain variables between classes
- From: "Jay Rimalrick" <email@hidden>
- Date: Tue, 16 Dec 2003 16:01:17 -0500
This additional information may help for an alternate approach ...
What I need is for a delegate method of AClass to tell some of the information
of MainClass. Is there anyway to make data of MainClass global ... even
though this isn't the best way to access the data. Or is there some was for
ACLass to get the data of MainClass through a function. Please not that
MainClass had data in it so it simply cannot be declared by AClass and
accessed.
any and all help is greatly appreciated
-j
---------- Original Message ----------------------------------
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.
>
________________________________________________________________
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.