I have a modal view controller that creates core data changes in it's own context, and when I click done, it saves the changes (that dispatches the merge changes notification), notifies the delegate and dismisses.
My problem is that I need the delegate to receive the message after my main context has merged with the changes of the editing context. I want the delegate call to take place on the next run loop but I'm having problems with object lifetimes. I've thought of the following:
- Make call to
[delegate performSelector:withObject:afterDelay:]
however it seems that that message is not recognised. My delegate conforms to theNSObject
protocol but that doesn't include the perform selector with delay. - Create a method in my view controller:
informDelegateWithObject:
that calls the delegate method, and call that method after a delay. I.e.[self performSelector:@selector(informDelegateWithObject:) withObject:.. afterDelay:..]
. This could work, however, as my view controller is being dismissed, if the delay is several seconds then it would have been released from memory and wouldn't that cause a crash when it comes to invoking? - Create an instance of
NSInvocation
. I have thought about this, however, what is the lifetime of this object? If I create it using[NSInvocation invocationWithMethodSignature:]
then wouldn't theNSInvocation
object be autoreleased, and not be around for the next run loop? Let alone several seconds. And as my modal view controller is being dismissed and released, I can't store the invocation object in my view controller.
Any suggestions?