I make a singleton like this:
+ (CurrentUser *)sharedInstance {
static id sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
It has a property called:
@property (nonatomic, strong) NSData *profilePicData;
I save an image like this:
[[CurrentUser sharedInstance] setProfilePicData:profilePictureData];
I load the image like this:
if ([[CurrentUser sharedInstance]profilePicData]) {
self.profileImageView.image = [UIImage imageWithData:[[CurrentUser sharedInstance]profilePicData]];
}
The image shows up and everything is good, but when I restart the app and go to the same view controllers that contain this same code, the image no longer appears in the UIImageView
. This leads me to believe the singleton is not persisting.
How do I persist the data across app restarts with a singleton object?