h3dkandi h3dkandi - 1 month ago 5
Objective-C Question

What comes first applicationWillResignActive app delegate method or the Notification for the same event?

In my app delegate I save(persist) an object when the

applicationWillResignActive:
method is called. I have a view controller which responds to
UIApplicationWillResignActiveNotification
and makes a modification to the previously mentioned object but doesn't save(persist) the object itself.
What I need to know is if that change will be persisted trough the
applicationWillResignActive:
method or if I should explicitly save it in the view controller just to be sure?

Edit:
NSLog
test result is: 1st is the delegate method, 2nd it is the Notification method.

I wasn't sure the test would guarantee me that the order will be the same every time because I don't know how notification center works. That is why I posted the question before testing and giving results.

Answer

The documentation for applicationWillResignActive: says, "After calling this method, the app also posts a UIApplicationWillResignActiveNotification notification to give interested objects a chance to respond to the transition."

The "after" makes me believe that you will not get the changed value inside applicationWillResignActive:.

Of course, inserting a couple of NSLog lines would let you prove the order of operation for yourself.

Comments