NSNotificationCenter trapping and tracing all NSNotifications

The only solution I got to work was using breakpoints. I added a breakpoint at __CFXNotificationPost_old (CoreFoundation) and bundled that with a Debugger Command po {NSNotification *}($ebp+12). All of this is nicely doable within the Xcode GUI: click on “Run” on the Xcode application menu (top of the screen) select “Debugger” within the Debugger window … Read more

How to use Notification.Name extension from Swift to Objective-C?

My extension in swift file extension Notification.Name { static let purchaseDidFinish = Notification.Name(“purchaseDidFinish”) } @objc extension NSNotification { public static let purchaseDidFinish = Notification.Name.purchaseDidFinish } // OBJECTIVE-C #import YourProjectName-Swift.h [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(purchaseDidFinish) name:NSNotification.purchaseDidFinish object:nil]; // SWIFT NotificationCenter.default.addObserver(self, selector: #selector(purchaseDidFinish), name: .purchaseDidFinish, object: nil) @objc func purchaseDidFinish(notification: Notification) { print(“purchaseDidFinish”) } @leanne’s answer was super helpful

How to avoid adding multiple NSNotification observer?

One way to prevent duplicate observers from being added is to explicitly call removeObserver for the target / selector before adding it again. I imagine you can add this as a category method: @interface NSNotificationCenter (UniqueNotif) – (void)addUniqueObserver:(id)observer selector:(SEL)selector name:(NSString *)name object:(id)object { [[NSNotificationCenter defaultCenter] removeObserver:observer name:name object:object]; [[NSNotificationCenter defaultCenter] addObserver:observer selector:selector name:name object:object]; } … Read more

Text change notification for an NSTextField

If you just want to detect when the value of a text field has changed, you can use the controlTextDidChange: delegate method that NSTextField inherits from NSControl. Just connect the delegate outlet of the NSTextField in the nib file to your controller class, and implement something like this: – (void)controlTextDidChange:(NSNotification *)notification { NSTextField *textField = … Read more

Objective-C: Where to remove observer for NSNotification?

The generic answer would be “as soon as you no longer need the notifications”. This is obviously not a satisfying answer. I’d recommend, that you add a call [notificationCenter removeObserver: self] in method dealloc of those classes, which you intend to use as observers, as it is the last chance to unregister an observer cleanly. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)