I have a C++ class that I recently renamed from *.cpp to *.mm to support objective-c. So I can add the following objective-c code.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(notificationHandler:)
name:@"notify"
object:nil];
- How do/Can I write the notificationHandler method in c++?
- Will setting addObserver:self property work?
You’d need an Objective-C class to handle Objective-C notifications. Core Foundation to the rescue!
In.. wherever you start listening for notifications, e.g. your constructor:
When done, e.g. in your destructor:
And finally, a static function to handle the dispatch:
Ta da!