ios - 编辑 plist 中的现有数据

标签 ios xcode plist

如何通过编码检查数据是否已经存在后覆盖 plist 中的现有数据

详细说明:

我将用户名和密码保存在位于文档目录中的 plist 文件中。现在如果用户选择更改密码选项,plist 应该检查他的用户名是否存在。如果存在,则他输入的新密码应覆盖 plist 中的现有密码。

谁能帮我写一段示例代码

最佳答案

您不能更改存储在应用程序包中的 plist。 如果需要编辑存储在plist中的用户数据,则需要在文档目录下创建plist。

另一个选项是 NSUserDefaults .如果有大量数据,那么我会建议使用 sqlite3 数据库,否则您可以使用 plistNSUserDefaults

您可以像这样更改 plist 的值:

NSString *path = //your plist path in document directory;
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
NSString *userExist = [plistDict objectForKey:@"UserName"]; //test the user exist
if([userExist isEqualToString:@"Midhun"])                   //checking user exist or not
{
  NSString *userPwd = @"Midhun";
  [tempDict setObject:userPwd forKey:@"PassWord"]; //Password is your key
  [tempDict writeToFile:path atomically:YES];
}

请引用这个link更多。 这是一个 plist tutorial给你。

关于ios - 编辑 plist 中的现有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13009768/

相关文章:

ios - 使用 UIAlertViewStylePlainTextInput 显示 UIAlertView,但不显示键盘

iphone - 如何在不从 xcode 构建/运行的情况下测试 iPhone 应用程序性能和网络使用情况

ios - 在 UICollectionView 中的单元格上创建 View

ios - Entitlements.plist 与 Appname.Entitlements

iphone - 使用plist/XML下载缓存明细数据?

ios - 当 NSDictionary 添加到数组中时,它会替换之前的字典

iphone - Xcode 在服务器上上传 plist 文件 (iPhone)

ios - 使用 AutoLayout Storyboard 更改 iPhone 屏幕尺寸的 ImageView 大小

iphone - 尝试并捕获iPhone中的功能

iphone - 帮助!仪器无法启动