Pb implementing shared instance
Pb implementing shared instance
- Subject: Pb implementing shared instance
- From: "Kubernan @ 10191 Technologies" <email@hidden>
- Date: Sat, 20 Nov 2004 15:18:37 +0100
Hello,
After reading the archive mailing list (and some web pages) i'm still not able
to implement a shared instance (!).
I have a compilation warning and i don't understand why :
compiling classB.m
" classA may not respond to '-sharedInstance' "
What i need is to establish a reference of class A in class B.
If you have an idea ...
Here's my code :
file classA.h
@interface classA : NSObject {
// other...
}
+(classA *)sharedInstance;
// other ..
@end
file classA.m
#import classA.h
@implementation classA
static classA *_sharedInstance = nil;
+(classA *)sharedInstance
{
static classA *_sharedInstance = nil;
if (_sharedInstance == nil)
_sharedInstance = [[self alloc) init];
return _sharedInstance;
}
@end
I use the shareInstance here :
file classB.h
#import classA.h
@interface classB : NSObject {
classA *classARef;
// other...
}
-(void)setAReferanceToClassA:(classA *)aData;
file classB.m
#import "classB.h"
@implementation classB
-(void)setAReferanceToClassA:(classA *)aData
{
classARef = [aData sharedInstance]; // <-- THE COMPIL WARNING (!?)
}
@end
Thanks a lot,
K.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden