Re: functions vs methods
Re: functions vs methods
- Subject: Re: functions vs methods
- From: Nicko van Someren <email@hidden>
- Date: Thu, 5 May 2005 14:56:04 +0100
On 5 May 2005, at 14:24, Roland Silver wrote:
Given one of my classes, Foo, how can I define a function (not method)
post() which accesses an instance variable textView of Foo? The
following doesn't work:
@interface Foo : NSObject
{
IBOutlet NSTextView *textView;
}
...
void post(const char *template, ...) {
...
[textView insertText:nsMsg]; //<------- error: 'textView' undeclared
} //end post
The name textView is only bound by the compiler inside the
@implementation block. If you are outside that but you mark an
instance variable with @public then you can still access that instance
variables of the class as if a class pointer were a structure pointer,
e.g.
@interface Foo : NSObject
{
@public
IBOutlet NSTextView *textView;
}
...
void post(const char *template, Foo *fooPtr, ...) {
...
[fooPtr->textView insertText:nsMsg];
}
Nicko
_______________________________________________
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