views:

62

answers:

3

Here is my code:

//ECHOAppDelegate.m
@implementation ECHOAppDelegate
 ...
 @end

//PtyView.m
 @interface PtyView (PtyPrivate)
 -(void)startTask;
 -(void) didRead: (NSNotification *)fileNoty;
 @end

 @implementation PtyView
 ...
 -(void)startTask {
 //starts task
 }
 @end

Now, how do I trigger "startTask" from ECHOAppDelegate.m? I need to create an instance? I'm a total beginner :D

Any example code would be awesome!

Thanks, Elijah

A: 

self represent the current object.

You just need to call the method like that.

[self startTask];
gcamp
A: 

-(void)startTask; appears to be private implementation and in theory should not be called from external classes.

To answer your question, you can call it something like this:

PtyView *v = [[PtyView alloc] init];
[v startTask];
[v release];

Though you will get a warning saying, PtyView might not respond to startTask. Since it is not in public interface of class.

Update: Above code assumes that when startTask returns, you are done with this object. But something tells me that you might be using async callbacks. If that is the case then startTask might return immediately and you won't release it then and there. Normally in this case, you will be notified by PtyView about the completion of task. So you release it when the task is complete.

Update2: Making a method public is easy. You just declare it in the public interface (the header file of class):

//in PtyView.h
@interface PtyView
-(void)startTask;
@end

//in PtyView.m
@implementation PtyView
...
-(void)startTask {
//starts task
}
@end

Notice that there is no category defined in the interface declaration.

Hemant
How would I then make startTask public?
Elijah W.
Updated the answer!
Hemant
A: 

How about subclassing ECHOAppDelegate? (Then make sure PtyView inherits from NSObject?)

// cf. http://amath.colorado.edu/pub/mac/programs/PseudoTTY.zip

@interface ECHOAppDelegate : PtyView
...
@end

@implementation ECHOAppDelegate
- (id) init
{
   self = [super init];
   if (!self) return nil;
   ...
   return self;
}

...
   [self startTask];
...
@end
tim