0
<SaveDbstr: 0x8b640e0> (entity: SaveDbstr; id: 0x8b64140 <x-coredata:///SaveDbstr/tC0D35B09-8B89-4233-A572-8DA6434884802> ; data: {
cityName = LAFAYETTE;
distance = "11,382.7";
driverId = 00000000097;
strainDescription = "This is no creeper! Effects are felt almost immedi";
strainId = 00000000001;
strainImage = "www.dbster.net/DbsterDocuments/StrainImages/Kandy Skunk1.jpg";
strainName = "Kandy Skunk";
strainTypeName = "Hash and Oil";
vendorBusinessName = "Raging Vaping";
vendorDriverEngagementId = 18;
vendorOverallRating = "4.3";
})
2015-02-17 09:57:56.722 CoreDatProject[570:70b] save data to core data <SaveDbstr: 0x8b042f0> (entity: SaveDbstr; id: 0x8b028b0 <x-coredata:///SaveDbstr/tC0D35B09-8B89-4233-A572-8DA6434884803> ; data: {
cityName = MENIFEE;
distance = "11,382.7";
driverId = 00000000112;
strainDescription = "This is no creeper! Effects are felt almost immedi";
strainId = 00000000001;
strainImage = "www.dbster.net/DbsterDocuments/StrainImages/Kandy Skunk1.jpg";
strainName = "Kandy Skunk";
strainTypeName = "Hash and Oil";
vendorBusinessName = Vendor1;
vendorDriverEngagementId = 20;
vendorOverallRating = "4.1";
})

save the above objects successfully in core data by using below code

@property (nonatomic,strong) NSManagedObjectContext *savedbstr;

savedbstr = [self managedObjectContext];
for (int i=0;i<[temp count]; i++) {
    SaveDbstr *savedoobstr = [NSEntityDescription
                                 insertNewObjectForEntityForName:@"SaveDbstr"
                                 inManagedObjectContext:self. savedbstr];
    [savedoobstr setValuesForKeysWithDictionary:[temp objectAtIndex:i]];


}

NSError *error1;
if (![self. savedbstr save:&error1]) {
    NSLog(@"Coudld not save %@",[error1 localizedDescription]);
}

How can I update values of core data objects with same attributes but different values ? For Example I want to update cityName of first object ?? thank you

Vicky iOS
  • 35
  • 11
  • You need to fetch the entity from Core Data into its object form, then modify the `cityName` value and finally call `save:` method on your `managedObjectContext` again to save that change. – Zhang Feb 17 '15 at 05:34
  • You need t fetch that value that you wan to update then change its value and commit instead here you are inserting the new record that is not correct. See the following stack question: – jogshardik Feb 17 '15 at 05:35
  • how can i fetch the first object because two objects have same entity name, please clarify!! – Vicky iOS Feb 17 '15 at 05:40
  • You need to take some unique key in you core data attribute based on that you can identify the object you want to update, and i have also post my answer please see that. – jogshardik Feb 17 '15 at 06:25

1 Answers1

0

You need to fetch that value that you wan to update then change its value and commit instead here you are inserting the new record that is not correct. See the following stack question:

How to update existing object in Core Data?

Community
  • 1
  • 1
jogshardik
  • 1,446
  • 1
  • 12
  • 23