
概述plist
文件是标准的xml文件,在cocoa中可以很简单地使用。这里介绍一下使用方法: 以下代码在Mac和iPhone中均适用。
写入plist文件: NSMutableDictionary * dict = [ [ NSMutableDictionary alloc ] initWithContentsOfFile :@"/Sample.plist" ] ; [ dict
pList文件是标准的xml文件,在cocoa中可以很简单地使用。这里介绍一下使用方法:
以下代码在Mac和iPhone中均适用。
写入pList文件:
NSMutableDictionary * dict =
[ NSMutableDictionary alloc ] initWithContentsOffile :@
"/Sample.pList" ] ;
[ dict
setobject : @
"Yes" forKey : @
"RestartSpringBoard" writetofile : @
atomically :
YES ] ;
读取pList文件:
NSMutableDictionary * dict =
] ;
Nsstring *
object =
objectForKey : @
] ;
//读pList 文件
到 NSMutableDictionary 中 dictpList = [[NSMutableDictionary alloc ] initWithContentsOfURL:[NSURL fileURLWithPath:path]]; [dictpList setobject:@"testOne" forKey:@"key1"]; NSLog([dictpList objectForKey:@"key1"]); NSArray *array = [[NSArray alloc] initWithObjects:@"item1",@"item2",@"item3",nil]; [dictpList setobject:array forKey:@"arrayitemtest"]; [dictpList writetofile:pListPath atomically:YES]; Nsstring *name = [dictpList objectForKey:@"name" ]; NSLog(name); arrayList = [[NSMutableArray alloc] initWithArray:[dictpList objectForKey:@"arrayitemtest"]]; //从NSMutableDictionary 中构建 pList 文件 NSArray *array = [[NSArray alloc] initWithObjects:@"item1",nil]; dictpList = [[NSMutableDictionary alloc ] init]; [dictpList setobject:@"nameOne" forKey:@"name"]; [dictpList setobject:array forKey:@"item"]; [dictpList writetofile:pListPath atomically:YES]; //arrayList = [[NSMutableArray alloc] init]; //[arrayList addobject:[dictpList objectForKey:@"name"]]; arrayList = [[NSMutableArray alloc] initWithArray:[dictpList objectForKey:@"item"]]; 总结
以上是内存溢出为你收集整理的iPhone读取和写入plist文件全部内容,希望文章能够帮你解决iPhone读取和写入plist文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)