将数据添加到plist
|
我想在代码中创建一个plist,并从用户输入中添加更多“记录”。我已经创建了一个plist,我可以编写用户输入,但是不能将数据添加到我的plist中。每次,它都保存最后的输入并仅保留一个“记录”。这是代码:
-(void) createPlistFile {
manager = [NSFileManager defaultManager];
filepath = @\"/Users/agnostos_el/Downloads/PhoneBook/PhoneBook/Epafes.txt\";
if ( [manager fileExistsAtPath:filepath] == NO )
{
NSLog(@\"Το Αρχειο Δεν Υπαρχει Το δημειουργω\");
[[NSFileManager defaultManager]createFileAtPath:filepath contents:nil attributes:nil];
}
}
-(void) openPlistFile {
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if( [path count] > 0 ){
pListFile = [[path objectAtIndex:0] stringByAppendingPathComponent:filepath];
NSDictionary *pListDict = [[NSDictionary alloc]initWithContentsOfFile:filepath];
if ( [pListDict count] <= 0 )
{
}
[self createPlistFile];
}
}
- (void) times
{
filepath = @\"/Users/agnostos_el/Downloads/PhoneBook/PhoneBook/Epafes.txt\";
stoixeia = [NSArray arrayWithObjects:onoma.stringValue, poli.stringValue, odos.stringValue, per.stringValue, tk.stringValue, xora.stringValue,kin.stringValue, kin1.stringValue, kin2.stringValue, kat.stringValue, erg.stringValue, fax.stringValue, email.stringValue, email1.stringValue, email2.stringValue, pros.stringValue, sim.stringValue, nil];
eponimos = epitheto.stringValue;
NSMutableDictionary *atomo = [NSMutableDictionary dictionary];
innerDict = [NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects: eponimos, stoixeia, nil]
forKeys:[NSArray arrayWithObjects:@\"eponimo\", @\"stoixeia\", nil]];
[atomo setObject:innerDict forKey:eponimos];
id plist = [NSPropertyListSerialization dataFromPropertyList:(id)atomo
format:NSPropertyListXMLFormat_v1_0 errorDescription:nil];
record = [[NSData alloc]initWithData:plist];
[record writeToFile:filepath atomically:YES];
}
- (void) eggrafi
{
[self openPlistFile];
[self times];
}
有什么建议么?谢谢。
没有找到相关结果
已邀请:
1 个回复
茬贺努充尽
: