Data Serialization


SQLine Demo:http://www.wuleilei.com/blog/264


NSKeyedUnarchiver http://285746555.blog.51cto.com/2966432/647312
NSValue、CGPoint 序列化的问题等


  • 文件、属性列表
  • 对象归档
  • SQLite
  • Core Data



NSUserDefaults
NSFileHandle
NSFileManager
NSUserDefaults


	NSString * msg = [NSString stringWithFormat:@"%d : %@\n", i, [NSDate date]];
	NSString * path = 。。。;
	
	NSFileHandle *fh = [NSFileHandle fileHandleForWritingAtPath:path];
	[fh seekToEndOfFile];
	[fh writeData:[msg dataUsingEncoding:NSUTF8StringEncoding]];
	[fh closeFile];



[NSFileManager defaultManager]//单例
[[NSFileManager alloc]init] //  线程安全



//  NSFileManager的方法介绍
http://apps.hi.baidu.com/share/detail/38263560
//  遍历文件、目录
http://kevin-wu.net/tips-for-using-nsfilemanager-to-get-filefolder-list/
//  文件排序
http://www.acwind.net/blog/?p=1116





NSUserDefaults
http://www.cnblogs.com/zengwu/archive/2011/02/25/1964908.html

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@"111" forKey:@"myTest"];
[defaults synchronize];//写入disk

NSString *testStr = [defaults objectForKey:@"myTest"];//再次读出
NSLog(@"testStr is: %@",testStr);



NSString * path = [[NSBundle mainBundle] pathForResource:@"default" ofType:@"json"];


第8章枚举目录
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) 
{
	//	可变的Array
	NSMutableArray *files = [NSMutableArray arrayWithCapacity:0];
	
	//	目录管理对象
	NSFileManager *manager = [NSFileManager defaultManager];

	//	~	用户主目录
	NSString *homeDir = [@"~" stringByExpandingTildeInPath];
	NSDirectoryEnumerator *dirEnum = [manager enumeratorAtPath:homeDir];
	
	
	//	枚举文件
	for (NSString *fileName; fileName = [dirEnum nextObject];)
	{
		if ([[fileName pathExtension] isEqualTo:@"jpg"]) 
		{	
			[files addObject:fileName];
		}
	}
	
	
	//	快速枚举
	for (NSString *fileName in files)
		NSLog(@"%@", fileName);	
	
	/*
	 //普通枚举
	NSEnumerator *fileEnum = [files objectEnumerator];
	while (fileName = [fileEnum nextObject]) {
		NSLog(@"%@", fileName);
	}
	*/
	
  return 0;
}



第三章读文件
#import <Foundation/Foundation.h> 

int main (int argc, const char * argv[]) 
{	
	NSLog(@"file path = %s",argv[1]);
	
	
	FILE *file = fopen(argv[1], "r"); 
	char buf[128] = {0}; 
	
	while (fgets(buf, 128, file)) 
	{ 
		buf[strlen(buf) - 1] = '\0'; 
		NSLog(@"length = %d,content = %s",strlen(buf), buf); 
	} 
	
	return 0; 
}

你可能感兴趣的:(serialization)