实现在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是苹果为多核开发提供的解决方案 多线程最常见的问题就是读写,比如数据库读写,文件读写,读取是共享的,写是互斥,允许多 ...
随机推荐
- 关于KeyEvent.Callback
keycode------------>KEYCODE_BACK,KEYCODE_MENU event.getAction------->ACTION_DOWN,ACTION_UP,ACT ...
- NEC红外遥控协议理解与实现
红外发射管有2个管脚,发送的是经过38KHz时钟调制过的信号.例如下图使用PWM产生一个等占空时钟信号用于调制. 接收管收下来的信号已经经过了解调,可以直接连接系统的外部中断脚. 下面通过逻辑分析仪来 ...
- File.ReadAllText 读取中文乱码问题
原文:File.ReadAllText 读取中文乱码问题 用 File.ReadAllText(filepath) 去读取中文txt文件会遇到乱码问题,我自己测试了一下,ANSI编码的txt才会出 ...
- C语言 EOF是什么?
Linux中,在新的一行的开头,按下Ctrl-D,就代表EOF(如果在一行的中间按下Ctrl-D,则表示输出"标准输入"的缓存区,所以这时必须按两次Ctrl-D):Windows中 ...
- 使用StoryBoard设置Scrollview的横向滚动不用一行代码
1).创建一个空工程Single类型的工程,然后打开故事版(StoryBoard)在ViewController上添加scrollview 2).然后对scrollview添加约束,上下左右全部都是0 ...
- mysql 1449 : The user specified as a definer ('montor'@'%') does not exist
grant all privileges on *.* to root@"%" identified by "."; flush privileges;
- ASP.NET 4.0升级至ASP.NET 4.5需要注意的地方 【转】
原以为只要在Visual Studio 2012中将每个项目的Target framework设置为.NET Framewor 4.5进行编译,然后在web.config中设置compilation的 ...
- 让你提前认识软件开发(23):怎样在C语言中运行shell命令?
第1部分 又一次认识C语言 怎样在C语言中运行shell命令? [文章摘要] Linux操作系统具备开源等诸多优秀特性,因此在很多通信类软件(主流开发语言为C语言)中,开发平台都迁移到了Linux上, ...
- mysql jdbc 查询连接问题
做了一个测试,mysql jdbc 链接A调用setAutoCommit,设置false,查询指定数据,可以查询出来,另个一链接把指定的数据给删除了,第一个链接在此查询的时候,仍然可以查询出来,使用的 ...
- Android Studio无法关联Api23源码-提示Souces for android api 23 platform not found
最近升级了As,然后忽然就关联不上源码了,很不方便,找个Activity的源码都只有outline没有解释,还提示这个错误: Decompiled .class file, bytecode vers ...