实现在ios文件读写
文件都是用来读写数据的,可是哪里都会有潜规则,ios里面读写数据的潜规则你知不知道,你知道不知道!!!
你有没有觉得NSUserDefaults和NSBundle,plist这些玩意阴魂不散,有时候搞不清楚谁是谁。谁又会在哪里出现
看看下面,NSUserDefaults里面基本没存啥啊,只有语言国度对不对,剩下的是自己填的,是嘛
[NSUserDefaults standardUserDefaults]可以用来保存:NSString, NSNumber, NSDate, NSArray, NSDictionary。
系统默认保存到/Library/Preferences/.plist这个文件中
写入数据:
//Bool
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:YES forKey:@"switchValue"];
//String
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:@"star" forKey:@"inputValue"];
读取数据:
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
BOOL sw = [userDefaults boolForKey:@"switchValue"];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *str = [userDefaults stringForKey:@"inputValue"];
默认的
[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]:{
AppleITunesStoreItemKinds = (
eBook,
document,
"software-update",
booklet,
"itunes-u",
newsstand,
artist,
podcast,
"podcast-episode",
software
);
AppleLanguages = (
"zh-Hans",
en,
fr,
de,
ja,
nl,
it,
es,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ko,
"zh-Hant",
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
ca,
hu,
vi
);
AppleLocale = "en_US";
NSInterfaceStyle = macintosh;
NSLanguages = (
"zh-Hans",
en,
fr,
de,
ja,
nl,
it,
es,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ko,
"zh-Hant",
ru,
pl,
tr,
uk,
ar,
hr,
cs,
el,
he,
ro,
sk,
th,
id,
ms,
"en-GB",
ca,
hu,
vi
);
}
NSBundle这斯里面存了比NSUserDefaults里面多得多的东西啊,怎么分配的哦
程序版本号,程序名称,路径,启动nib,好嘛。。。。
NSBundle mainBundle:{
CFBundleDevelopmentRegion = English;
CFBundleDisplayName = iVersion;
CFBundleExecutable = iVersion;
CFBundleExecutablePath = "/Users/yongjack/Library/Application Support/iPhone Simulator/6.1/Applications/D0556446-FFD6-4C33-81F2-5917B48907F6/iVersion.app/iVersion";
CFBundleIdentifier = "com.charcoaldesign.iVersion";
CFBundleInfoDictionaryVersion = "6.0";
CFBundleInfoPlistURL = "Info.plist -- file://localhost/Users/yongjack/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/D0556446-FFD6-4C33-81F2-5917B48907F6/iVersion.app/";
CFBundleName = iVersion;
CFBundlePackageType = APPL;
CFBundleSignature = "????";
CFBundleSupportedPlatforms = (
iPhoneSimulator
);
CFBundleVersion = "1.0";
DTPlatformName = iphonesimulator;
DTSDKName = "iphonesimulator6.1";
LSRequiresIPhoneOS = 1;
NSBundleInitialPath = "/Users/yongjack/Library/Application Support/iPhone Simulator/6.1/Applications/D0556446-FFD6-4C33-81F2-5917B48907F6/iVersion.app";
NSBundleResolvedPath = "/Users/yongjack/Library/Application Support/iPhone Simulator/6.1/Applications/D0556446-FFD6-4C33-81F2-5917B48907F6/iVersion.app";
NSMainNibFile = MainWindow;
UIDeviceFamily = (
1
);
UISupportedInterfaceOrientations = (
UIInterfaceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft,
UIInterfaceOrientationLandscapeRight
);
}
NSCachesDirectory <Application_Home>/Library/Caches
NSApplicationSupportDirectory <Application_Home>/Library/Application Support
实现在ios文件读写的更多相关文章
- Apache POI 实现对 Excel 文件读写
1. Apache POI 简介 Apache POI是Apache软件基金会的开放源码函式库. 提供API给Java应用程序对Microsoft Office格式档案读和写的功能. 老外起名字总是很 ...
- iOS 文件读写
#import <Foundation/Foundation.h> @interface Utils : NSObject +(void) writeFile:(NSString *) f ...
- C#实现对Word文件读写[转]
手头上的一个项目报表相对比较简单,所以报表打印采用VBA引擎,通过定制Word模版,然后根据模版需要填充数据,然后OK,打印即可. 实现方法:首先需要引用VBA组建,我用的是Office2003 Pr ...
- iOS数据持久化文件读写之偏好设置
很多iOS应用都支持偏好设置,比如保存用户名.密码.字体大小等设置,iOS提供了一套标准的解决方案来为应用加入偏好设置功能.每个应用都有个NSUserDefaults实例,通过它来存取偏好设置.比如, ...
- Cocos2d-x在win32,android和IOS下的文件读写问题
最近在学习和使用Cocos2d-x框架,虽然说的是跨平台,但是在用VS进行开发,然后移植到android或IOS下,也可能会出现各种问题,需要做细微的调整. 例如我在做文件读写操作的时候,很可能在wi ...
- ios本地文件内容读取,.json .plist 文件读写
ios本地文件内容读取,.json .plist 文件读写 本地文件.json .plist文件是较为常用的存储本地数据的文件,对这些文件的操作也是一种常用的基础. 本文同时提供初始化变量的比较标准的 ...
- ios 简单的plist文件读写操作(Document和NSUserDefaults)
最近遇到ios上文件读写操作的有关知识,记录下来,以便以后查阅,同时分享与大家. 一,简单介绍一下常用的plist文件. 全名是:Property List,属性列表文件,它是一种用来存储串行化后的对 ...
- iOS文件和文件夹的创建,删除,移动, 拷贝,是否存在及简单数据类型的读写
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...
- 【iOS】线程安全的文件读写
前段时间看了一遍GCD(Grand Central Dispatch)多线程,GCD是苹果为多核开发提供的解决方案 多线程最常见的问题就是读写,比如数据库读写,文件读写,读取是共享的,写是互斥,允许多 ...
随机推荐
- 淘宝api 开发_获取用户信息
string url = "http://gw.api.taobao.com/router/rest"; "; string appsecret = "fdf7 ...
- Struts2 请求处理步骤
1) 客户端初始化一个指向Servlet容器(例如Tomcat)的请求 2 )这个请求经过一系列的过滤器(Filter)(这些过滤器中有一个叫做ActionContextCleanUp的可选过滤器 ...
- Repeated meta-data items
B.2 Generating your own meta-data using the annotation processor You can easily generate your own co ...
- html5 notifications通知
http://www.html5rocks.com/en/tutorials/notifications/quick/?redirect_from_locale=zh http://www.paulu ...
- uva 10382 Watering Grass_贪心
题意:给你个矩形n*m,再给你n个圆的圆心坐标和半径,问最用最少用几个圆把这个矩形覆盖 思路:直接想发现这问题不容易,后来发现可以把圆看做区间(能把矩形面积覆盖),然后这个问题就容易解决了 #incl ...
- bat命令学习笔记
1.一般在开始声明 setlocal enabledelayedexpansion 设置本地为延迟扩展.其实也就是:延迟变量,全称延迟环境变量扩展,使得批处理能够感知到变量的动态变化,在运行过程中给变 ...
- hdu 4711 Weather概率dp
http://acm.hdu.edu.cn/showproblem.php?pid=4711 真的是坑吐血了,wa了5次 最后实在无语 把long long double 改成long double ...
- 网易云课堂_C++开发入门到精通_章节4:运算符重载
课时23运算符重载 运算符重载 重载赋值运算符 Person& Person::operator=(const Person& other) { //检查自赋值 if (this == ...
- opengl笔记——旋转,一段代码的理解
重看:opengl笔记——OpenGL好资料备忘 在找到这段代码,对理解opengl旋转很有帮助 ... glPushMatrix(); // initialze ModelView matrix g ...
- css 中文字体 unicode 对照表
css 中文字体可以用 unicode 格式来表示,比如“宋体”可以用 \5B8B\4F53 来表示.具体参考下表: 中文名 英文名 unicode 宋体 SimSun \5B8B\4F53 黑体 S ...