FROM : Kubernan @ 10191 Technologies
DATE : Sat Nov 20 15:18:37 2004
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.
DATE : Sat Nov 20 15:18:37 2004
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.
| Related mails | Author | Date |
|---|---|---|
| Kubernan @ 10191 T… | Nov 20, 15:18 | |
| Robbie Haertel | Nov 20, 17:04 |






Cocoa mail archive

