views:

78

answers:

2

Ok here is my code so far:

@implementation PtyView

- (id)initWithFrame:(NSRect)frame;
{
    if (self = [super initWithFrame: frame])
    {
        [self setFont:[NSFont fontWithName:@"Courier" size:0.0]];
        [self startTask];
    }
    return self;
}

- (void)keyDown:(NSEvent *)event
{
    const char * typein = [[event characters] UTF8String];
    [masterHandle
     writeData:[NSData dataWithBytes:typein length:strlen(typein)]];
}
...
@end

the problem is that I want to trigger "startTask" from another implementation but, if I just "startTask" it won't display the output because I didn't use initWithFrame.

How would I do this?

Thanks, Elijah

A: 

If you want to call startTask from somewhere else without first creating an instance of PtyView then startTask must be a static method, not an instance method.

Put this in your @interface:

+ (void)startTask;

Put this in your @implementation

+ (void)startTask
{
    // Code goes here
}

Put this when you want to call it:

[PtyView startTask];

Notes: The + means it's a static method. You cannot access instance variables from a static method.

jhabbott
Yes, but see my problem? I have initWithFrame that starts the task when the program starts. I want to start the ask somewhere else in my code. BUT, I can't because without init frame, the task won't print the output. Any ideas?
Elijah W.
You're not being clear about what you want to do. It sounds like you might want a singleton though, but that's just a guess.
jhabbott
well, instead of initWithFrame starting when the program starts, can it be call-able? What do you mean by singleton? can you show an example?
Elijah W.
A: 

Well, I think, you are looking for something like the "Execute" button in AMShellWrapperTest.app for your (version of) PseudoTTY.app ( http://amath.colorado.edu/pub/mac/programs/PseudoTTY.zip ). Right?

marko
basically, yes :D BUT, I need to send data to a running task, I cannot do that with AMshellWrapper. Any ideas?
Elijah W.