简体   繁体   中英

How to update values of core data objects with same attributes but different values?

<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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM