PerformSelectorOnMainThreadメソッドを右に使用しています(インスタンス化された新しいManagedObjectContextの変更をマージするには)?
私は私の操作でこのような何かを行う(CTXである私のインスタンス化MOC):通知の
まずレジスタ:次に
// Register context with the notification center
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(mergeChanges:)
name:NSManagedObjectContextDidSaveNotification
object:ctx];
あなたがコンテキスト保存する必要があります。
if ([ctx hasChanges]) {
error = nil;
// Save the context.
if (![ctx save:&error])
{
// Do something with the error
}
// Clear out the scratchpad
[ctx reset];
}
を
そして、メインMOCとマージする方法:
- (void)mergeChanges:(NSNotification *)notification
{
id appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *mainContext = [appDelegate managedObjectContext];
// Merge changes into the main context on the main thread
[mainContext performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:)
withObject:notification
waitUntilDone:NO];
// NSLog(@"Merged Changes");
}
ホープこれは
はい、私はこれを使用することができますが、私は、デリゲートが、私は私の別の作成したコンテキストを保存した場合、それが別のスレッドに保存されていないので、私はエラーが出るようmainThreadに呼ばれているので、それがクラッシュすると思います。これは私の提案ですが、これは問題ではないかもしれません。 – MoFuRo
NSOperation内でASINetworkQueueをインスタンス化することはできませんし、そこにデリゲートメソッドも処理しますか?私はこれと同じ種類のことを行いますが(ASIHttpRequestを使用しています)、NSOperation内のデリゲートメソッドを処理するとうまくいきます。 –