gpt4 book ai didi

iphone - 谁能帮我将数据附加到 plist 文件中?

转载 作者:行者123 更新时间:2023-11-29 04:45:42 26 4
gpt4 key购买 nike

我已经尝试使用此代码将我的数据复制到 plist,但在附加的情况下它不起作用。任何人都可以建议我一种附加数据的好方法吗?
NSMutableDictionary *nameDictionary = [NSMutableDictionary 字典];

NSString *plistPath=[[NSBundle mainBundle] pathForResource:@"listNew" ofType:@"plist"];
[nameDictionary setValue:nameEntered.text forKey:@"name"];
[nameDictionary setValue:company.text forKey:@"company"];
[nameDictionary setValue:designation.text forKey:@"designation"];

// create dictionary with values in UITextFields
NSMutableArray *plist = [NSMutableArray arrayWithContentsOfFile:plistPath];
if (plist == nil) plist = [NSMutableArray array];
[plist addObject:nameDictionary];
[plist writeToFile:plistPath atomically:YES];
UIAlertView *tellErr = [[UIAlertView alloc] initWithTitle:title message:@"succsefully created" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[tellErr show];
nameEntered.text=@"";
company.text=@"";
designation.text=@"";

最佳答案

您应该使用+[NSKeyedArchiver archiveRootObject:toFile:]将 Array 对象存档到文件。并使用+[NSKeyedUnarchiver unarchiveObjectWithFile:]取消存档。

关于iphone - 谁能帮我将数据附加到 plist 文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9668362/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com