RestKit 0,20 - Jaki jest preferowany sposób tworzenia nowego obiektu NSManagedObject?
Ciekawe, jaki jest najlepszy sposób na stworzenie nowego obiektu NSManagedObject w RestKit 0.20? Obecnie mój kod wygląda mniej więcej tak:
#pragma mark - navigation buttons
- (void)createButtonDidTouch
{
// create new album object
NSManagedObjectContext *context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
NSManagedObjectContext *parentContext = RKObjectManager.sharedManager.managedObjectStore.mainQueueManagedObjectContext;
context.parentContext = parentContext;
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Album" inManagedObjectContext:parentContext];
Album *newAlbum = [[Album alloc] initWithEntity:entityDescription insertIntoManagedObjectContext:context];
// pass object to create view to manipulate
AlbumCreateViewController *createViewController = [[AlbumCreateViewController alloc] initWithData:newAlbum];
createViewController.delegate = self;
createViewController.managedObjectContext = context;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:createViewController];
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:navController animated:YES completion:nil];
}
#pragma mark - create view controller delegate
- (void)createViewControllerDidSave:(NSManagedObject *)data
{
// dismiss the create view controller and POST
// FIXME: add restkit code to save the object
NSLog(@"save the object...");
NSDictionary *userInfo = [KeychainUtility load:@"userInfo"];
NSString *path = [NSString stringWithFormat:@"/albums/add/%@/%@", userInfo[@"userID"], userInfo[@"apiKey"]];
[RKObjectManager.sharedManager postObject:data path:path parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
operation.targetObject = data;
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"create album error: %@", error);
}];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)createViewControllerDidCancel:(NSManagedObject *)data
{
// dismiss the create view controller
NSLog(@"delete the object...");
// FIXME: add restkit code to delete the object
[self dismissViewControllerAnimated:YES completion:nil];
}
Jestem również ciekawy, jakie są moje obowiązki związane z zapisywaniem / usuwaniem tego obiektu. Jeśli I POST do serwera przez RestKit jest zapisany kontekst obiektu zarządzanego?
Co się stanie, jeśli zdecyduję się anulować ten proces tworzenia - jaki jest preferowany sposób usunięcia tego obiektu?
Zasadniczo, ile kosztuje dla mnie RestKit i co powinienem zrobić, aby to zrobić. Nie znalazłem zbyt wielu dokumentów na ten temat i chciałbym się o tym dowiedzieć.