如何将数据写入plist [英] How to write the data to the plist
本文介绍了如何将数据写入plist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI
你可以给我发送示例代码,将数据添加到.plist中。 .my plist的格式如下。请帮助我
HI can u send me sample code to add the data to the .plist. .my plist was in this format as follows.kindly help me out
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>http://localhost:8888/sample</string>
<string>http://localhost:8888/sample</string>
</array>
</plist>
我将从实现代码中发送url字符串。请在此帮助我...
i wil send the url string from the implementation code.kindly help me in this pls..
-(IBAction)AddFieldid)sender;
{
NSMutableArray *myPrimaryinfo = [[NSMutableArray arrayWithCapacity:6]retain];
NSArray *keys = [NSArray arrayWithObjects:@"string",nil];
[myPrimaryinfo addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:
[NSString stringWithFormat:@"sample"],nil]forKeys:keys]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"urls.plist"];
[myPrimaryinfo writeToFile:path atomically:NO];
NSLog(@"PrimaryInfo array: %@", myPrimaryinfo);
}
谢谢
推荐答案
我想这样的东西会起作用(不太适合iphone的东西):
I guess something like this would work (not very good at iphone stuff):
// Loading
NSString *path = ...
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];
// Manipulating
NSObject *newElement = ...
[array addObject:newElement];
// Storing
[array writeToFile:path atomically:YES];
按ALT+双击类名打开此课程的文档以及方法列表等。看看那里!
By pressing "ALT" + double clicking on a class name opens up the docu for this class along with a list of methods and so on. Take a look there, too!
这篇关于如何将数据写入plist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文