[newVehicle setValue: _txtFieldVehicleNumber.text forKey:@\"number\"];
[newVehicle setValue: lblFuelType.text forKey:@\"fueltype\"];
[newVehicle setValue: lblFuelU
Get an entity from core data:
VVdAppDelegate *delegate = (VVdAppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *managedObjectContext = [delegate managedObjectContext];
NSEntityDescription *entityDescriptionDelegate = [NSEntityDescription entityForName:@"entityName" inManagedObjectContext:managedObjectContext];
NSFetchRequest *requestData = [[NSFetchRequest alloc] init];
[requestData setEntity:entityDescriptionDelegate];
NSError *error;
If there are more than an NSManagedObject
NSArray *objectsArray = [managedObjectContext executeFetchRequest:requestData error:&error];
for (NSManagedObject *object in objectsArray) {
// Here update values of every object
}
// And save values to core data
[managedObjectContext save:&error];
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]