I’m using a Singleton class and following is the code:
.h File:
#import <Foundation/Foundation.h>
@interface Credential : NSObject {
NSString *UID;
NSString *UPASS;
}
@property(nonatomic,retain) NSString *UID;
@property(nonatomic,retain) NSString *UPASS;
static Credential *credential = NULL;
+(Credential*) sharedInstance;
/*
+ @property(nonatomic,retain) NSString *UID;
+ @property(nonatomic,retain) NSString *UPASS;
*/
@end
.m file:
#import "Credential.h"
@implementation Credential
@synthesize UID,UPASS;
-(void) dealloc{
[UID release];
[UPASS release];
[super dealloc];
}
+(Credential*) sharedInstance
{
@synchronized(self)
{
if (credential == NULL) {
credential = [[Credential alloc] init];
}
}
return credential;
}
@end
The following line produces warning “defined but not used”
static Credential *credential = NULL;
I couldn’t figure out that I’ve been using credential variable in .m file under “sharedInstance” function then why am I getting this warning?
A strange issue to me!
Does the problem go away when you move the static variable to the top of the implementation (
.m) file? And on a related note, I think that you would benefit from getting rid of the singleton altogether.