Re: Passing variables between .m files
Re: Passing variables between .m files
- Subject: Re: Passing variables between .m files
- From: BareFeet <email@hidden>
- Date: Thu, 10 Sep 2009 20:39:39 +1000
Hi Aaron,
I have been struggling over this one for a while now, and what
frustrates me
the most is the feeling that it should be relatively simple to do.
Let's say I have File1.m and File2.m, and I would like to access a
variable
in File2.m from File1.
My previous programming experience is in Java, so my first
impression was to
do this (in the File1 implementation file):
File2.outletVariable = varFile1;
I asked a similar question a few days ago, and was helped out by the
same Graham who answered you. I feel your pain and confusion.
The answer is pretty simple, assuming we're talking about the same
thing.
I'm assuming you have two classes, depicted in your File1.m and
File2.m files, and you have an object of each class in your nib file.
You need to add an outlet in File1.h that you can link to the File2
object, like this:
// File1.h
@class File2;
@interface File1 : NSObject
{
IBOutlet File2* linkToFile2;
}
Once that is saved in XCode, switch over to Interface Builder, control-
drag from your File1 object to your File2 object. The popup menu
should show "linkToFile2", select it.
Now you can call any method in File2 from File1. If you want to access
an instance variable in the File2 object, such as (NSString*)
myVariable, then you will need to create an accessor method for it in
File2, such as:
- (NSString*) myVariable
{
return myVariable;
}
Then you can refer to it from File1 via:
[linkToFile2 myVariable];
Hope this helps you as much as Graham helped me. If not, flip back to
his answers to my question about a week ago.
Tom
BareFeet
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden