Hey guys, here's my situation. Without spoiling too much of the surprise, I've got a Core Data application that has (in the data model) two Entities of type Assignment and Archive.
An Assignment entity has a few attributes, such as an NSString name, a Date dueDate, and a few other types of things. What I'm wondering is how to take an assignment object and "move" it to the archive entity. I know this sounds weird, as my terminology probably isn't quite right.
Essentially, I've achieved this "somewhat" with the below code:
Where assignmentController and archiveAssignmentController are the NSArrayController linked to the two entities. The way above works, but I have to set all of the keys manually, and each Assignment actually has a "To-Many" relationship to another entity that I would like to transfer as well. What I was thinking was something like:
But even though this compiles fine, it doesn't quite work right. Any ideas? Thanks so much in advance, I don't know what I'd do without you guys.
An Assignment entity has a few attributes, such as an NSString name, a Date dueDate, and a few other types of things. What I'm wondering is how to take an assignment object and "move" it to the archive entity. I know this sounds weird, as my terminology probably isn't quite right.
Essentially, I've achieved this "somewhat" with the below code:
Code:
NSManagedObjectContext * context = [[NSApp delegate] managedObjectContext];
NSManagedObject * myObject = [[assignmentController selectedObjects] objectAtIndex:0];
myObject = [NSEntityDescription insertNewObjectForEntityForName: @"ArchiveAssignment" inManagedObjectContext: context];
[myObject setValue:[[[assignmentController selectedObjects] objectAtIndex:0] valueForKey:@"name"] forKey:@"name"];
[myObject setValue:[[[assignmentController selectedObjects] objectAtIndex:0] valueForKey:@"priority"] forKey:@"priority"];
[myObject setValue:[[[assignmentController selectedObjects] objectAtIndex:0] valueForKey:@"dueDate"] forKey:@"dueDate"];
[archiveAssignmentController addObject:myObject];
[assignmentController removeObjectAtArrangedObjectIndex: [assignmentTableView selectedRow]];
Where assignmentController and archiveAssignmentController are the NSArrayController linked to the two entities. The way above works, but I have to set all of the keys manually, and each Assignment actually has a "To-Many" relationship to another entity that I would like to transfer as well. What I was thinking was something like:
Code:
[archiveController addObject:[[assignmentsController selectedObjects] objectAtIndex:0]];
[assignmentsController removeObjectAtArrangedObjectIndex:[assignmentTableView selectedRow]];
But even though this compiles fine, it doesn't quite work right. Any ideas? Thanks so much in advance, I don't know what I'd do without you guys.