[newVehicle setValue: _txtFieldVehicleNumber.text forKey:@"number"];
[newVehicle setValue: lblFuelType.text forKey:@"fueltype"];
[newVehicle setValue: lblFuelUnit.text forKey:@"fuelunit"];
[newVehicle setValue: lblDistanceUnit.text forKey:@"distanceunit"];
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]