I create an NSOperation every time my app launches or resigns active. I need to queue them with dependencies such that two never execute at the same time, but one after another.
Is it safe to do this?
- Hold a strong reference to the NSOperation object in the App Delegate.
- When the app resigns active, simply check if hat property is not nil.
- If it is not nil, check if the current NSOperation
-isFinished
. - If it's finished, just add the new one to the queue.
- If it's not finished yet, create the new one and set a dependency on the running one, then add it to the queue.
I'm concerned a bit with multithreading issues here. The documentation of the -isFinished or -addDependency: methods doesn't say they should not be called from the main thread. So I guess it is ok to do that.
Edit: The NSOperation performs some file system operations in the background.