当前位置:网站首页>保存和检索字符串
保存和检索字符串
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
边栏推荐
- The relationship between root and coefficient of quadratic equation with one variable
- Method return value considerations
- [daily] win10 system setting computer never sleeps
- Why rdd/dataset is needed in spark
- Solution to the problem of UOS boot prompt unlocking login password ring
- bat脚本学习(一)
- Vit paper details
- 记一次清理挖矿病毒的过程
- Why is the cluster mode of spark on Yan better than the client mode
- 缓存更新策略概览(Caching Strategies Overview)
猜你喜欢

Four common ways and performance comparison of ArrayList de duplication (jmh performance analysis)

uni-app App端半屏连续扫码

jvm:大对象在老年代的分配

Z function (extended KMP)

袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求

Persistence / caching of RDD in spark

numpy 下载安装

Vit paper details

Earned value management EVM detailed explanation and application, example explanation

JPEG2000 matlab source code implementation
随机推荐
小满网络模型&http1-http2 &浏览器缓存
Basic introduction of figure
Happy sound 2[sing.2]
Microsoft technology empowerment position - February course Preview
The role of applicationmaster in spark on Yan's cluster mode
ROS error: could not find a package configuration file provided by "move_base“
LeetCode:1189. The maximum number of "balloons" -- simple
Univariate cubic equation - relationship between root and coefficient
互联网快讯:吉利正式收购魅族;胰岛素集采在31省全面落地
Efficiency tool +wps check box shows the solution to the sun problem
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
14 years Bachelor degree, transferred to software testing, salary 13.5k
JPEG2000 matlab source code implementation
[Li Kou brush questions] 32 Longest valid bracket
Proxy and reverse proxy
From campus to Tencent work for a year of those stumbles!
十一、服务介绍及端口
JPEG2000-Matlab源码实现
14年本科毕业,转行软件测试,薪资13.5K
Divide candy