I have a class defined in a an external pair of files, let’s name them engine.h and engine.m . Also, it was given to me the file “engineListener.h”.
this is how they look:
File engine.h:
@interface coreEngine: NSObject {
NSString *displaydValue;
id <coreEngineListener> listener;
}
-(coreEngine*)initWithListener:(id <coreEngineListener>) _listener;
//...
File engine.m
//imports here
@interface coreEngine()
-(Boolean) MyOperation: ... ... (etc)
@end
File engineListener.h
//imports here...
@class coreEngine;
@protocol coreEngineListener <NSObject>
@required
-(void) someVariable:(coreEngine *)source;
@end
Now, in my myController.h I have this:
//... imports and include ...
@interface myController : NSObject
{
coreEngine *PhysicsEngine;
}
- (IBAction)doSomething:(id)sender;
And in the myController.m this is what I have:
-(id) init
{
NSAutorelease *pool = [[NSAutoreleasePool alloc] init];
coreEngine *PhysicsEngine = [[coreEngine alloc] init];
[PhysicsEngine release];
[pool drain];
return self;
}
- (IBAction)doSomething:(id)sender
{
[PhysicsEngine MyOperation:Something];
}
The thing now is: the code compiles correctly, but the “[PhysicsEngine MyOperation:Something]” is doing nothing. I’m sure I’m instantiating my class wrongly. The NSObject defined in “engine.h engine.m and enginelistener.h” that I have to load was not made by me, and I have no means to modify it.
I’ve tried doing some dummy/random things based on what I’ve seen around on the internet, without knowing 100% what I was doing. I’m not even close to be familiar with ObjectiveC or C/C++, so be gentle with me. I’m totally noob on this subject.
I’m using Xcode 4, and I have also access to XCode 3.2.6
How should I load my class properly?
Any advice is welcome.
Thanks
Your class’s
-initshould look something like this:This follows a standard design pattern for initializing classes. You actually do the initialization by calling
-initonsuper. Afterwards, ifselfwas initialized properly (as it almost always will be), you create yourPhysicsEngineobject. Note that your class needs to conform to thePhysicsEngineListenerprotocol and implement-someVariable:.