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

时间:2011-04-14 10:09:41

标签: iphone 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文件中使用凭证变量,那为什么我会收到此警告?

给我一​​个奇怪的问题!

1 个答案:

答案 0 :(得分:3)

将静态变量移动到实现.m)文件的顶部时,问题是否会消失?在相关的说明中,我认为您将完全受益于getting rid of the singleton