Re: functions vs methods
Re: functions vs methods
- Subject: Re: functions vs methods
- From: Ricky Sharp <email@hidden>
- Date: Thu, 05 May 2005 08:34:14 -0500
On Thursday, May 05, 2005, at 08:24AM, Roland Silver <email@hidden> 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:
>
>// Foo.h
>#import <Cocoa/Cocoa.h>
>#import <stdio.h>
>@interface Foo : NSObject
>{
> IBOutlet NSTextView *textView;
>}
>... method declarations ...
>
>void post(const char *template, ...);
>@end
>
>// Foo.m
>@implementation Foo
>... method definitions ...
>
>void post(const char *template, ...) {
> va_list args;
> char *msg;
> NSString *nsMsg;
> va_start(args, template);
> vasprintf(&msg, template, args);
> va_end(args);
> nsMsg = [NSString stringWithCString:msg];
> [textView insertText:nsMsg]; //<------- error: 'textView' undeclared
>} //end post
>@end
I would rewrite your C function to just return the string. The various calling methods could then use the string as needed. Furthermore, I'd move the function to just another module (i.e. not live in your class' implementation).
--
Rick Sharp
Instant Interactive(tm)
_______________________________________________
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