Note that there are some explanatory texts on larger screens.

plurals
  1. PORestKit 0.20 — What is the preferred way to create a new NSManagedObject?
    primarykey
    data
    text
    <p>I'm curious to know what the best way is to create a new NSManagedObject in RestKit 0.20? Currently my code looks something like this:</p> <pre><code>#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]; } </code></pre> <p>I'm also curious to know what my responsibilities are for saving / deleting this object. If I POST to the server via RestKit is the managed object context saved?</p> <p>What if I decide to cancel this creation process — what's the preferred way to delete this object?</p> <p>Basically how much is RestKit doing for me, and what should I make sure I'm doing. I haven't found much documentation on this and would like to be clear on it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload