说明 |
|
首次发布 |
2017年05月23日 |
最近更新 |
2018年09月04日 |
#import <Foundation/Foundation.h>
#define MZUserManager [MZAccountManager shareManager]
static NSString *const kUserManagerKey = @"kUserManagerKey";
@interface MZAccountManager : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *mobileNo;
+ (instancetype)shareManager;
- (void)updateUserData;
- (void)resetUserData;
@end
#import "MZAccountManager.h"
//Libs
#import <MJExtension/MJExtension.h>
static MZAccountManager *instance = nil;
static dispatch_once_t onceToken;
@implementation MZAccountManager
+ (instancetype)shareManager {
dispatch_once(&onceToken, ^{
if (!instance) {
instance = [[MZAccountManager alloc] init];
[instance getUserData];
}
});
return instance;
}
- (void)getUserData {
NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:kUserManagerKey];
[self mj_setKeyValues:dict];
}
- (void)updateUserData {
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
[userDefault setObject:[self mj_JSONObject] forKey:kUserManagerKey];
[userDefault synchronize];
}
- (void)resetUserData {
instance = nil;
onceToken = 0l;
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
[userDefault removeObjectForKey:kUserManagerKey];
[userDefault synchronize];
}
@end