Programmatically Update an attribute in Core Data

前端 未结 5 728
被撕碎了的回忆
被撕碎了的回忆 2020-12-23 15:11

I\'ve looked through all the class documentation for Core Data and I can\'t find away to programmatically update values in a core data entity. For example, I have a structur

5条回答
  •  滥情空心
    2020-12-23 15:49

    NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
    
    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
    
            NSArray *temp = [[NSArray alloc]initWithObjects:@"NewWord", nil];
    
    
            [object setValue:[temp objectAtIndex:0] forKey:@"title"];
    
    
    
            // Save the context.
            NSError *error = nil;
            if (![context save:&error]) {
                NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
                abort();
            }
    

    I think this piece of code will give you the idea ;)

提交回复
热议问题