Objective C Singleton类“已定义但未使用”警告!

问题描述

| 我正在使用Singleton类,下面是代码: .h文件
#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文件
#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
以下行产生警告“已定义但未使用”
   static Credential *credential = NULL;
我无法弄清楚我在\“ sharedInstance \”函数下的.m文件中一直使用凭据变量,那么为什么收到此警告? 给我一个奇怪的问题!     

解决方法

将静态变量移至实现(
.m
)文件顶部时,问题是否消失了?在相关说明中,我认为完全摆脱单例将使您受益。