我單身的設置:的iOS:屬性值在辛格爾頓
//UserProfile.h
@property (nonatomic, retain) NSString * firstName;
@property (nonatomic, retain) NSString * lastName;
+(UserProfile *)sharedInstance;
//UserProfile.m
+(UserProfile *)sharedInstance
{
static UserProfile *instance = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
if (instance == nil){
instance = [[UserProfile alloc]init];
}
});
return instance;
}
調用辛格爾頓:
UserProfile *profileSharedInstance = [Profile sharedInstance];
profileSharedInstance = [responseObject firstObject];
NSLog (@"[UserProfile sharedInstance].lastName %@", [UserProfile sharedInstance].lastName);
NSLog (@"profileSharedInstance.lastName %@", profileSharedInstance.lastName);
登錄:
2014-03-31 05:47:50.557 App[80656:60b] [UserProfile sharedInstance].lastName (null)
2014-03-31 05:47:50.557 App[80656:60b] profileSharedInstance.lastName Smith
問題:爲什麼[UserProfile sharedInstance].lastName
空?它不應該也是「Smith
」?
你設置'profileSharedInstance = [responseObject firstObject]',什麼是responseObject? – bsarr007