当前位置:网站首页>保存和检索字符串
保存和检索字符串
2022-07-06 13:45:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
有时,有些事情需要存储在手机,比方说,在APP保存和使用的时间考虑password什么
需要编写方法的几个例子
在.h文件里写上方法名
+ (void) saveCenterProValue:(NSString*)valueStr key:(NSString *)keyStr;
+ (id)getCenterPro:(NSString*)identifier;
在.m文件里加上实现方法
ps:写在单例中更好
+ (void) saveCenterProValue:(NSString*)valueStr key:(NSString *)keyStr{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:valueStr forKey:keyStr];
[defaults synchronize];
}
+ (id)getCenterPro:(NSString*)identifier{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
return [defaults objectForKey:identifier];
}
好了,这样就完毕了
接下来。是怎样使用这种方法
1.使用宏定义
#define UserPass @“UserPass” //用户password
#define UserID @“UserID” //用户ID
2.保存某个字符串
[Common saveCenterProValue:@”123456″ key:UserPass];
[Common saveCenterProValue:@”001″ key:UserID];
3.获取这个字符串
Common getCenterPro:UserPass];
Common getCenterPro:UserID];
版权声明:本文博主原创文章,博客,未经同意不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117073.html原文链接:https://javaforall.cn
边栏推荐
- 记一次清理挖矿病毒的过程
- Technology sharing | packet capturing analysis TCP protocol
- 快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
- Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces
- Intelligent online customer service system source code Gofly development log - 2 Develop command line applications
- Realization of epoll reactor model
- 抖音將推獨立種草App“可頌”,字節忘不掉小紅書?
- MySQL removes duplicates according to two fields
- 50个常用的Numpy函数解释,参数和使用示例
- Description of web function test
猜你喜欢

Summary of cross partition scheme
![[Chongqing Guangdong education] Information Literacy of Sichuan Normal University: a new engine for efficiency improvement and lifelong learning reference materials](/img/a5/94bdea3a871db5305ef54e3b304beb.jpg)
[Chongqing Guangdong education] Information Literacy of Sichuan Normal University: a new engine for efficiency improvement and lifelong learning reference materials

Michael smashed the minority milk sign

快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”

Basic introduction of figure

The golden age of the U.S. technology industry has ended, and there have been constant lamentations about chip sales and 30000 layoffs

Five wars of Chinese Baijiu

Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces
![Happy sound 2[sing.2]](/img/ca/1581e561c427cb5b9bd5ae2604b993.jpg)
Happy sound 2[sing.2]

Why rdd/dataset is needed in spark
随机推荐
Is it important to build the SEO foundation of the new website
Fzu 1686 dragon mystery repeated coverage
50个常用的Numpy函数解释,参数和使用示例
The underlying implementation of string
Sparkshuffle process and Mr shuffle process
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)
一行代码可以做些什么?
LeetCode学习记录(从新手村出发之杀不出新手村)----1
guava:创建immutableXxx对象的3种方式
Web开发小妙招:巧用ThreadLocal规避层层传值
14 years Bachelor degree, transferred to software testing, salary 13.5k
Write a rotation verification code annotation gadget with aardio
Redistemplate common collection instructions opsforhash (IV)
跨分片方案 总结
Proxy and reverse proxy
Why does MySQL index fail? When do I use indexes?
guava:Collections. The collection created by unmodifiablexxx is not immutable
Sequoia China, just raised $9billion
抖音將推獨立種草App“可頌”,字節忘不掉小紅書?
搜素专题(DFS )