IOS 登录信息类(使用单例)

WCUserInfo.h

#import <Foundation/Foundation.h>
#import "Singleton.h"

@interface WCUserInfo : NSObject

singleton_interface(WCUserInfo);

@property (nonatomic ,copy)NSString *user ;
@property (nonatomic ,copy)NSString *pwd;

/**
 *登陆的状态 YES 登录过 NO 注销
 *
 */
@property (nonatomic, assign) BOOL  loginStatus;

@property (nonatomic ,copy)NSString *registerUser;
@property (nonatomic ,copy)NSString *registerPwd;

/**
 *
 *从沙盒里获取用户数据
 */
-(void)loadUserInfoFromSanbox;

/**
 *
 *保存用户数据到沙盒
 */
-(void)saveUserInfoToSanbox;

@end
View Code

WCUserInfo.m

#import "WCUserInfo.h"
#define  UserKey @"user"
#define LoginStatusKey @"LoginStatus"
#define PwdKey @"pwd"

@implementation WCUserInfo
singleton_implementation(WCUserInfo)

/**
 *
 *从沙盒里获取用户数据
 */
-(void)loadUserInfoFromSanbox{

   NSUserDefaults *defaults= [NSUserDefaults standardUserDefaults];
    [defaults setObject:self.user forKey:UserKey];
    [defaults setBool:self.loginStatus forKey:LoginStatusKey];
    [defaults setObject:self.pwd forKey:PwdKey];
    [defaults synchronize];
}

/**
 *
 *保存用户数据到沙盒
 */
-(void)saveUserInfoToSanbox{

    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
   self.user= [defaults objectForKey:UserKey];
    self.loginStatus=[defaults boolForKey:LoginStatusKey];
    self.pwd=[defaults objectForKey:PwdKey];

}
@end
View Code

 

posted on 2017-06-13 13:06  守望星空  阅读(1117)  评论(0编辑  收藏  举报

导航