当前位置:网站首页>保存和检索字符串
保存和检索字符串
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
边栏推荐
- From campus to Tencent work for a year of those stumbles!
- Description of web function test
- 华为在多个行业同时出击,吓人的技术让欧美企业瑟瑟发抖
- What can one line of code do?
- 红杉中国,刚刚募资90亿美元
- [Chongqing Guangdong education] Tianjin urban construction university concrete structure design principle a reference
- Why does MySQL index fail? When do I use indexes?
- Persistence / caching of RDD in spark
- [Yu Yue education] higher mathematics of Nanchang University (2) reference materials
- 新入职一家公司需要去实践和注意的内容
猜你喜欢
![[daily] win10 system setting computer never sleeps](/img/94/15f5a368e395b6948f409c5f6fc871.jpg)
[daily] win10 system setting computer never sleeps
![Leetcode topic [array] -118 Yang Hui triangle](/img/77/d8a7085968cc443260b4c0910bd04b.jpg)
Leetcode topic [array] -118 Yang Hui triangle

AI 企业多云存储架构实践 | 深势科技分享

It's not my boast. You haven't used this fairy idea plug-in!
Why does MySQL index fail? When do I use indexes?

C how to set two columns comboboxcolumn in DataGridView to bind a secondary linkage effect of cascading events

Reptile practice (V): climbing watercress top250
![Happy sound 2[sing.2]](/img/ca/1581e561c427cb5b9bd5ae2604b993.jpg)
Happy sound 2[sing.2]

Five wars of Chinese Baijiu

Fastjson parses JSON strings (deserialized to list, map)
随机推荐
bat脚本学习(一)
mysql根据两个字段去重
Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
Leveldb source code analysis series - main process
[Digital IC manual tearing code] Verilog automatic beverage machine | topic | principle | design | simulation
Univariate cubic equation - relationship between root and coefficient
11、 Service introduction and port
uni-app App端半屏连续扫码
功能强大的国产Api管理工具
C language: comprehensive application of if, def and ifndef
Intelligent online customer service system source code Gofly development log - 2 Develop command line applications
Huawei has launched attacks in many industries at the same time, and its frightening technology has made European and American enterprises tremble
14 years Bachelor degree, transferred to software testing, salary 13.5k
The relationship between root and coefficient of quadratic equation with one variable
Binary tree node at the longest distance
One line by line explanation of the source code of anchor free series network yolox (a total of ten articles, you can change the network at will after reading it, if you won't complain to me)
Z function (extended KMP)
PostgreSQL install GIS plug-in create extension PostGIS_ topology
LeetCode:1189. The maximum number of "balloons" -- simple
设置状态栏样式Demo