2011-04-14 3 views
0

나는 싱글 톤 클래스를 사용하고 있으며 다음과 같은 코드가있다 :목표 C 싱글 톤 클래스 "정의되었지만 사용되지 않음"경고!

.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 파일의 자격 증명 변수를 사용하고 있다는 것을 알아 채지 못했습니다. 그런 다음 왜이 경고 메시지가 나옵니까?

나에게 이상한 문제!

답변

3

정적 변수를 구현 (.m) 파일의 맨 위로 이동하면 문제가 해결됩니까? 그리고 관련 메모에서 나는 getting rid of the singleton의 혜택을 누리게 될 것이라고 생각합니다.

+0

+1 나를 바로 잡아주고 빠른 답변을 제공합니다. 9 분 전에 답을 표시해두기를 바랍니다. :) – necixy

+0

예하 !!! 이제 답을 정확하게 표시 할 수 있습니다. 당신은 친구를 흔들고 있습니다! 감사합니다. – necixy

+0

도와 드리겠습니다 :) – zoul