如何更新核心数据输入值

时间:2023-03-07
本文介绍了如何更新核心数据输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[newVehicle setValue: _txtFieldVehicleNumber.text forKey:@"number"];

[newVehicle setValue: lblFuelType.text forKey:@"fueltype"];

[newVehicle setValue: lblFuelUnit.text forKey:@"fuelunit"];

[newVehicle setValue: lblDistanceUnit.text forKey:@"distanceunit"];

我想更新名为Vehicle"的核心数据实体,对于该实体,我有几个属性,当我从实体中选择特定属性时,我想更新其中一些属性,但不是全部.那我该怎么办??

I want to update my core data entity named "Vehicle", for that entity I have several attributes and I want to update some of them but not all when I select particular attribute from the entity. So what should I do ??

推荐答案

您可以执行以下操作(近似代码.实现错误处理和检查语法).

you can do the following (approximate code. Implement error handling and check syntax).

NSFetchRequest *fetchRequest=[NSFetchRequest fetchRequestWithEntityName:@"Vehicle"];
NSPredicate *predicate=[NSPredicate predicateWithFormat:@"vehicle_id==%@",vehicle_id]; // If required to fetch specific vehicle
fetchRequest.predicate=predicate;
Vehicle *newVehicle=[[self.managedObjectContext executeFetchRequest:fetchRequest error:nil] lastObject];

[newVehicle setValue: _txtFieldVehicleNumber.text forKey:@"number"];

[newVehicle setValue: lblFuelType.text forKey:@"fueltype"];

[newVehicle setValue: lblFuelUnit.text forKey:@"fuelunit"];

[newVehicle setValue: lblDistanceUnit.text forKey:@"distanceunit"];

[self.managedObjectContext save:nil]

这篇关于如何更新核心数据输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:CoreData 上的 UserInfo 字典 下一篇:adb 安装失败:INSTALL_CANCELED_BY_USER

相关文章

最新文章