• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: functions vs methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >functions vs methods (From: Roland Silver <email@hidden>)

  • Prev by Date: Re: Library for User Management
  • Next by Date: Re: dragPromisedFilesOfTypes clears drag pasteboard
  • Previous by thread: Re: functions vs methods
  • Next by thread: Re: functions vs methods
  • Index(es):
    • Date
    • Thread