iphone 数据保存
来源:互联网 发布:starry night观星软件 编辑:程序博客网 时间:2024/05/19 17:04
NSString *str = @"abc";
NSString *astr = @"efg";
NSArray *Array = [NSArray arrayWithObjects:str, astr, nil];
//Save
NSString *Path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *filename = [Path stringByAppendingPathComponent:@"test"];
[NSKeyedArchiver archiveRootObject:Array toFile:filename];
str = @"a";
astr = @"";
//load
NSArray *arr = [NSKeyedUnarchiver unarchiveObjectWithFile: filename];
str = [arr objectAtIndex:0];
astr = [arr objectAtIndex:1];
NSLog(@"str:%@",str);
NSLog(@"astr:%@",astr);
2
NSString *str = @"abc";
NSString *astr = @"efg";
NSArray *Array = [NSArray arrayWithObjects:str, astr, nil];
//Save
NSUserDefaults *SaveDefaults = [NSUserDefaults standardUserDefaults];
[SaveDefaults setObject:Array forKey:@"SaveKey"];
str = @"a";
astr = @"";
//load
Array = [SaveDefaults objectForKey:@"SaveKey"];
str = [Array objectAtIndex:0];
astr = [Array objectAtIndex:1];
NSLog(@"str:%@",str);
NSLog(@"astr:%@",astr);
(3)
NSString *str = @"abc";
NSString *astr = @"efg";
NSArray *Array = [NSArray arrayWithObjects:str, astr, nil];
//Save
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
}
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"Savedatas.plist"];
[[NSArray arrayWithObjects:Array,nil] writeToFile:appFile atomically:NO];
//load
if([[NSFileManager defaultManager] fileExistsAtPath:appFile])
self.SaveDataArray = [NSMutableArray arrayWithContentsOfFile:appFile];
else
self.SaveDataArray = [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Savedatas" ofType:@"plist"]];
NSArray *strArray = [self.SaveDataArray objectAtIndex:0];
str = [strArray objectAtIndex:0];
astr = [strArray objectAtIndex:1];
(4)
-(BOOL) writeApplicationData:(NSDictionary *)data writeFileName:(NSString *)fileName{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
return NO;
}
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];
return ([data writeToFile:appFile atomically:YES]);
}
-(id) readApplicationData:(NSString *)fileName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];
NSDictionary *myData = [[[NSDictionary alloc] initWithContentsOfFile:appFile] autorelease];
return myData;
}
- iPhone NSUserDefaults 保存数据
- iphone 数据保存
- iPhone NSUserDefaults 保存数据
- ios iphone 如何序列化存储,保存数据。
- 学习笔记-- IPhone 中使用Sqlite 保存数据
- iphone保存数据/选项的5种方法
- ios iphone 如何序列化存储,保存数据。
- 如何将数据保存到iphone中,app删除后,数据依然存在,
- iphone文档保存
- iphone 文件保存策略
- iphone UIImageWriteToSavedPhotosAlbum 保存图片
- iphone UIImageWriteToSavedPhotosAlbum 保存图片
- iphone UIImageWriteToSavedPhotosAlbum 保存图片
- VCF-IPHONE通讯录保存
- 保存数据
- 保存数据
- 保存数据
- 数据保存
- oracle10g通过防火墙操作步骤
- ubuntu下git安装与使用笔记
- iframe的用法总结
- 国内外技术论坛的区别
- .NET中非对称加密算法的密钥的存储
- iphone 数据保存
- Intent Server Environment
- 查看Oracle执行计划的几种方法
- js实现页面跳转的几种方式
- iphone开发一些好的网站推荐
- 网络dos命令(二)
- ubuntu 11.04上oracle 11g r2的TNS-12541:TNS-12560:TNS-00511错误处理
- HDU 1370 Biorhythms
- websphere 内存溢出处理