私はRestKit 0.20で新しいNSManagedObjectを作成するのが最善の方法を知りたいのですか?現在、私のコードは次のようなものになります。RestKit 0.20 - 新しいNSManagedObjectを作成する方法は何ですか?
#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];
}
を私も自分の責任は、このオブジェクトを削除/保存するためのものであるかを知るために興味があります。 RestKitを使用してサーバーにPOSTすると、管理対象オブジェクトのコンテキストが保存されますか?
この作成プロセスをキャンセルする場合はどうなりますか?このオブジェクトを削除するにはどうすればよいですか?
RestKitは基本的に私にとって何をしているのですか、私は何をしているのかを確認する必要があります。私はこれに関する多くの文書を見つけられておらず、それについて明確にしたいと思います。
私は上記のコードでオブジェクトを作成したが、POSTリクエストを発生させずに、「作成」ビューコントローラをキャンセル/閉じるという方法でこのオブジェクトを削除しますか?ちょうど私のローカルNSMangedObjectContextを通して? –
上記のコードでは、コンテキストに挿入されていますが、保存されていません。ビューコントローラの解雇のコンテキストから削除することができます。しかし、** managedObjectStore.mainQueueManagedObjectContext'にオブジェクトを直接挿入するのではなく、作成コントローラにセグメンテーションしてそれをコントローラに割り当てるときに、子マネージドオブジェクトコンテキストを作成することをお勧めします。あなたが次に行うことができるのは、あなたが取り消すときにMOC deallocをさせるだけです。 –
子コンテキストを作成するためのショートカットはありますか?私は[Album createObject]のようなものを覚えています。 –