LoginMethods

来源:互联网 发布:知乎龙头股票有哪些 编辑:程序博客网 时间:2024/06/11 11:25
LoginMethods.h
+ (void)setLoginModel:(LoginModel *)loginModel;+ (LoginModel *)getLoginModel;+ (BOOL)judgeLogin;+ (void)logout;
+ (void)setLoginModel:(LoginModel *)loginModel {    [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:loginModel] forKey:loginModelKey];}+ (LoginModel *)getLoginModel {    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:loginModelKey];    LoginModel *loginModel = [NSKeyedUnarchiver unarchiveObjectWithData:data];    return loginModel;}+ (BOOL)judgeLogin {    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:loginModelKey];    LoginModel *loginModel = [NSKeyedUnarchiver unarchiveObjectWithData:data];    return loginModel;}+ (void)logout {    [[NSUserDefaults standardUserDefaults] removeObjectForKey:loginModelKey];}

//对LoginModel存储,需要使用YYModel,或者MJExtension归档,解档处理

#import "YYModel.h"@implementation LoginModel- (void)encodeWithCoder:(NSCoder *)aCoder {    [self yy_modelEncodeWithCoder:aCoder];}- (instancetype)initWithCoder:(NSCoder *)aDecoder {    self = [super init];    return [self yy_modelInitWithCoder:aDecoder];}@end


原创粉丝点击