Question

That's what I have :

Class A :

#import "ppCore.h"

@interface ppApplication : NSApplication {
    ppCore* core;
}

@property (assign) ppCore* core;

@end


@implementation ppApplication

@synthesize core;

- (void)awakeFromNib
{
    [self setCore:[[[ppCore alloc] init] retain]];
}

Class B :

#import "someObject.h"
#import "anotherObject.h"

@interface ppCore : NSObject<NSApplicationDelegate>  {
    ppSomeObject* someObject;
    ppAnotherObject* anotherObject;
}

@property (assign) ppSomeObject* someObject;
@property (assign) ppAnotherObject* anotherObject;

@end


@implementation ppCore

@synthesize someObject, anotherObject;

- (void)applicationDidFinishLaunching:(NSNotification *)notification 
{
     [self setSomeObject:[[ppSomeObject alloc] init]];
     [self setAnotherObject:[[ppAnotherObject alloc] init]];
}

And here's the issue :

AT SOME LATER STAGE, in ppApplication, I'm trying to have access to core.

core is there.

But, when I'm trying to access any of core's elements (e.g. [core someObject]), everything is turning up NULL (I've checked it in the Debugger)...

What am I doing wrong??

Was it helpful?

Solution

I suggest you remove the whole core thing since you can access your delegate through [[NSApplication sharedApplication] delegate] and move the setting of someObject and anotherObject to the delegate's init method.

OTHER TIPS

Have you tried declaring your objects like this:

@property (nonatomic, retain) ppCore* core;

@property (nonatomic, retain) ppSomeObject* someObject;
@property (nonatomic, retain) ppAnotherObject* anotherObject;

Antonio is right, bit you need to manage memory as well,

    #import "ppCore.h"

    @interface ppApplication : NSApplication {
        ppCore* core;
    }

    @property (nonatomic, retain) ppCore* core;

    @end


    @implementation ppApplication

    @synthesize core;

    - (void)awakeFromNib
    {
        ppCore* tempCore = [[ppCore alloc] init];   
        [self setCore: tempCore];
        [tempCore release];
    }

This might help.

Why do you believe - (void)applicationDidFinishLaunching: on your ppCore object is ever getting called? It seems to me you'll have to explicitly invoke it from somewhere.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top