BOOL变量在Singleton中返回NULL

时间:2014-07-22 14:06:20

标签: design-patterns ios7 singleton

我并不常常对此有任何疑问。

我刚回到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

My Singleton .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 个答案:

答案 0 :(得分:1)

  

@property BOOL *initialLogin;

虽然创建一个指向BOOL的指针的属性当然是可能的,但在这种情况下,您似乎要将其声明为BOOL而不是BOOL*。请尝试更改您的代码:

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

BOOL是标量类型,而不是类,因此您不需要使用指针引用BOOL