Reputation: 2074
I'm running the background process using this code:
func launchTor(hashedPassword hash : String) {
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)) {
// Do some stuff here
let observer = NSNotificationCenter.defaultCenter().addObserverForName("AppTerminates", object: nil, queue: nil) {
notification -> Void in
print("Terminating...")
// Do smh here
}
}
// Just some more stuff
}
Is there any way to specify the queue (GCD) that needs to catch the notification?
Upvotes: 0
Views: 203
Reputation: 4757
- addObserverForName:object:queue:usingBlock: method is an extra feature provided by NSOperationQueue class which is based on Grand Central Dispatcher:
Operation queues use the
libdispatch
library (also known as Grand Central Dispatch) to initiate the execution of their operations.
(from the beginning of the NSOperationQueue
class reference)
This feature can be re-implemented if there are reasons for that (e.g. different behaviour or educational purposes), otherwise it may be worth switching to NSOperationQueue
instead of bare GCD.
Upvotes: 1