三、ViewController 调用
//
// ViewController.m
// keyChainTest
//
// Created by Liyu on 2017/6/2.
// Copyright © 2017年 liyu. All rights reserved.
//
#import "ViewController.h"
#import "LYKeychainTool.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)saveBtn:(id)sender {
[LYKeychainTool saveKeychainValue:self.userNameTextField.text key:@"userName"];
[LYKeychainTool saveKeychainValue:self.passwordTextField.text key:@"password"];
}
- (IBAction)readeBtn:(id)sender {
self.userNameTextField.text = [NSString stringWithFormat:@"读取到用户名:%@",[LYKeychainTool readKeychainValue:@"userName"]];
self.passwordTextField.text = [NSString stringWithFormat:@"读取到用户密码:%@",[LYKeychainTool readKeychainValue:@"password"]];
}
- (IBAction)deleteBtn:(id)sender {
[LYKeychainTool deleteKeychainValue:@"userName"];
[LYKeychainTool deleteKeychainValue:@"password"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
四、效果如下图:

总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对ASPKU的支持。
注:相关教程知识阅读请移步到IOS开发频道。










