Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

phjo

macrumors regular
Original poster
Jan 8, 2008
149
1
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 :
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
 

phjo

macrumors regular
Original poster
Jan 8, 2008
149
1
Yes, thanks, I thought about that too (after I posted my message though, while reading online the objective-c documentation : http://objc.toodarkpark.net/ ) and almost answered myself except...

It (the code) looks nicer, but turns out to be quite the same as the trick I used : I need access to methods for both the classes that are defined in the header files, so I get lots of warnings at compile time by just declaring the class I want to use...

No problem at run time of course...

My guess right now is that, to get rid of these warnings, either I need to define a protocol for the class I instantiate without the header file, or use distributed objects for the child (cpu intensive task) to communicate with the controller... (I know nothing so far about distributed objects though, and again, I'd rather keep it simple !)

phjo
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.