Reputation: 22820
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]];
}
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??
Upvotes: 2
Views: 90
Reputation: 1684
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.
Upvotes: 1
Reputation: 86661
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.
Upvotes: 0
Reputation: 1543
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.
Upvotes: 1
Reputation: 20410
Have you tried declaring your objects like this:
@property (nonatomic, retain) ppCore* core;
@property (nonatomic, retain) ppSomeObject* someObject;
@property (nonatomic, retain) ppAnotherObject* anotherObject;
Upvotes: 2