Hi,
Say I have two classes, one is a controller, named AppController, derived from NSObject, and the other is a NSOperation, let's say BigThread, performing a cpu intensive task that won't stop by itself, but that has a stop: method that makes it finish properly.
The cpu intensive task from time to time involves changing some data and refreshing the display accordingly. The controller is in charge of the display.
The controller initiate the cpu intensive thread, keeping the id of the BigThread instance so that it can send stop: message when necessary.
The id of the controller is sent with the initialisation of the BigThread instance, so that the cpu intensive task can keep it and easily provide the controller with changes and new data...
The compiler won't allow this :
Appcontroller.h :
BigThread.h :
as it will refuse to build failing with a syntax error at the AppController *parent; line.
A fix is to replace AppController *parent; with, for example,
NSObject *parent; or even id parent;
but as you can guess, quite a few warnings occur then, the compiler not being sure the methods used apply to the object in question... (The executable works fine though...)
So what is the best practice here ?
- define a protocol to prevent the warnings ? (not sure how to do it right now, but I guess it might be possible)
- completely change the way the cpu intensive task communicate with the controller ? (I'd rather keep it simple there though...)
phjo
Say I have two classes, one is a controller, named AppController, derived from NSObject, and the other is a NSOperation, let's say BigThread, performing a cpu intensive task that won't stop by itself, but that has a stop: method that makes it finish properly.
The cpu intensive task from time to time involves changing some data and refreshing the display accordingly. The controller is in charge of the display.
The controller initiate the cpu intensive thread, keeping the id of the BigThread instance so that it can send stop: message when necessary.
The id of the controller is sent with the initialisation of the BigThread instance, so that the cpu intensive task can keep it and easily provide the controller with changes and new data...
The compiler won't allow this :
Appcontroller.h :
Code:
#import <Cocoa/Cocoa.h>
#import "BigThread.h"
@interface AppController : NSObject {
BigThread *process;
}
BigThread.h :
Code:
#import <Cocoa/Cocoa.h>
#import "AppController.h"
@interface BigThread : NSOperation {
AppController *parent;
}
as it will refuse to build failing with a syntax error at the AppController *parent; line.
A fix is to replace AppController *parent; with, for example,
NSObject *parent; or even id parent;
but as you can guess, quite a few warnings occur then, the compiler not being sure the methods used apply to the object in question... (The executable works fine though...)
So what is the best practice here ?
- define a protocol to prevent the warnings ? (not sure how to do it right now, but I guess it might be possible)
- completely change the way the cpu intensive task communicate with the controller ? (I'd rather keep it simple there though...)
phjo