当前位置:网站首页>保存和检索字符串
保存和检索字符串
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
边栏推荐
- What is the RDD operator in spark
- The relationship between root and coefficient of quadratic equation with one variable
- PostgreSQL 安装gis插件 CREATE EXTENSION postgis_topology
- 搜素专题(DFS )
- 在Pi和Jetson nano上运行深度网络,程序被Killed
- Web开发小妙招:巧用ThreadLocal规避层层传值
- Leveldb source code analysis series - main process
- guava:创建immutableXxx对象的3种方式
- Why does MySQL index fail? When do I use indexes?
- Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
猜你喜欢
麦趣尔砸了小众奶招牌
bat脚本学习(一)
Four common ways and performance comparison of ArrayList de duplication (jmh performance analysis)
Five wars of Chinese Baijiu
Checkpoint of RDD in spark
Why rdd/dataset is needed in spark
[Chongqing Guangdong education] Information Literacy of Sichuan Normal University: a new engine for efficiency improvement and lifelong learning reference materials
1292_ Implementation analysis of vtask resume() and xtask resume fromisr() in freeros
Leetcode topic [array] -118 Yang Hui triangle
C# 如何在dataGridView里设置两个列comboboxcolumn绑定级联事件的一个二级联动效果
随机推荐
Checkpoint of RDD in spark
JS learning notes OO create suspicious objects
Happy sound 2[sing.2]
AI 企业多云存储架构实践 | 深势科技分享
VIM basic configuration and frequently used commands
设置状态栏样式Demo
Fastjson parses JSON strings (deserialized to list, map)
1292_FreeROS中vTaskResume()以及xTaskResumeFromISR()的实现分析
JS method to stop foreach
爬虫实战(五):爬豆瓣top250
R3live notes: image processing section
记一次清理挖矿病毒的过程
NPM run dev start project error document is not defined
The relationship between root and coefficient of quadratic equation with one variable
新入职一家公司需要去实践和注意的内容
Guava: three ways to create immutablexxx objects
在最长的距离二叉树结点
Description of web function test
Earned value management EVM detailed explanation and application, example explanation
1D convolution detail