2014-07-22 82 views
0

我並不常見這個問題。BOOL在Singleton中返回NULL的變量

我剛回到Objective-C,它讓我頭疼。

我單身.H

@interface BFTDataHandler : NSObject 

+ (BFTDataHandler *)sharedInstance; 

@property BOOL *initialLogin; 
@property BOOL *PPAccepted; 
@property(nonatomic, retain) NSString *Username; 
@property(assign) NSString *EDEmail; 
@property(nonatomic, retain) NSString *UID; 
@property(assign) NSString *Longitude; 
@property(assign) NSString *Latitude; 

@end 

我辛格爾頓.M

#import "BFTDataHandler.h" 

@implementation BFTDataHandler 

-(id)init 
{ 
self = [super init]; 
if (self) { 
//initlize data 
    _Username = nil; 
    _EDEmail = nil; 
    _UID = nil; 
    _Longitude = nil; 
    _Latitude = nil; 
    _initialLogin = false; 
    _PPAccepted = false; 
} 
return self; 
} 

+ (BFTDataHandler *)sharedInstance 
{ 
static BFTDataHandler *_sharedInstance = nil; 
static dispatch_once_t onceSecurePredicate; 
dispatch_once(&onceSecurePredicate,^ 
       { 
        _sharedInstance = [[self alloc] init]; 
       }); 
return _sharedInstance; 
} 

我會嘗試訪問PPAccepted BOOL並不斷返回NULL

NSLog(@"%s", [[BFTDataHandler sharedInstance] PPAccepted]); 
return *[[BFTDataHandler sharedInstance]PPAccepted]; 

我找不出該問題,在此先感謝幫助

回答

1

@property BOOL *initialLogin;

雖然的確可以創建是一個指向BOOL的屬性,在這種情況下,它看起來像你的意思是它聲明爲一個BOOL而不是BOOL*。試着從而改變你的代碼:

@property BOOL initialLogin; // note that the '*' has been removed 
@property BOOL PPAccepted; 

BOOL是標量類型,而不是一類,所以你不需要指BOOL用指針。

+1

非常感謝你....有時它的深夜會讓人難以記起最簡單的事情哈哈 – Keeano