如何向现有实体的关系属性添加新对象

时间:2019-03-23 05:00:23

标签: objective-c core-data

如何将新对象添加到我现有实体的关系髋关节属性中。

我依靠将新对象添加到我现有的关系属性中,而不是添加新对象,而是保持更新我的关系属性中已经存在的值

    NSManagedObject *updateDevice = [self.playlistDataArray objectAtIndex:indexPath.row];


   NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"MoviesInsidePlaylist" inManagedObjectContext:[self managedObjectContext]];

   NSManagedObject *insideMoviesManagedObject = [[NSManagedObject alloc]initWithEntity:entityDescription insertIntoManagedObjectContext:[self managedObjectContext]];


    NSFetchRequest *fetchrequest = [[NSFetchRequest alloc] initWithEntityName:@"MovieDownloads"];
    self.moviesarray = [[[self managedObjectContext] executeFetchRequest:fetchrequest error:nil] mutableCopy];



    [insideMoviesManagedObject setValue:[[self.moviesarray objectAtIndex:self.SelectedTag]valueForKey:@"name"] forKey:@"mName"];
    [insideMoviesManagedObject setValue:[[self.moviesarray objectAtIndex:self.SelectedTag]valueForKey:@"path"] forKey:@"mPath"];
    [updateDevice setValue:[NSSet setWithObjects:manager, nil ] forKey:@"movieList"];


    // Save Managed Object Context
    NSError *error = nil;

    [updateDevice.managedObjectContext save:&error];
     [insideMoviesManagedObject.managedObjectContext save:&error];
    if (![updateDevice.managedObjectContext save:&error]) {
        NSLog(@"Unable to save managed object context.");
        NSLog(@"%@, %@", error, error.localizedDescription);
    }

我希望在我的核心数据关系属性中保存多个对象。

0 个答案:

没有答案