-2

An example: Why this Notification "didActivateApplicationNotification"

NSWorkspace.shared.notificationCenter.addObserver(self,
                    selector: #selector(updateOnFocus(notification:)),
                    name: NSWorkspace.didActivateApplicationNotification,
                    object:nil)

Pass Through Notification an User Info Dictionary -> Code below = Returned Notification

NSConcreteNotification 0x60000191e3d0 {name = NSWorkspaceDidActivateApplicationNotification; object = <NSWorkspace: 0x6000015443d0>; userInfo = {
    NSWorkspaceApplicationKey = "<NSRunningApplication: 0x60000394a800 (com.apple.ActivityMonitor - 6940) LSASN:{hi=0x0;lo=0x2aa2aa}>";
}}

And this Notification "activeSpaceDidChangeNotification"

NSWorkspace.shared.notificationCenter.addObserver(self,
                   selector: #selector(updateOnSpaceChange(notification:)),
                   name: NSWorkspace.activeSpaceDidChangeNotification,
                   object: nil)

Does not Pass an userInfo Dictionary through notification? -> Code below = Returned Notification

NSConcreteNotification 0x60000191e160 {name = NSWorkspaceActiveSpaceDidChangeNotification; object = <NSWorkspace: 0x6000015443d0>}

How can I padronize this notifications?

a_kira
  • 195
  • 10

1 Answers1

3

There is no "why" and no, you can't change this. These notifications come from the runtime. Some kinds of notification come with extra info in the userInfo, others don't. The way it works is the way it works. The end.

This is all perfectly well documented. The didActivate documentation says:

The notification object is the shared NSWorkspace instance. The userInfo dictionary contains the applicationUserInfoKey key with a corresponding instance of NSRunningApplication that represents the affected app.

So there's your user info. But the activeSpace documentation says:

The notification doesn’t contain a userInfo dictionary.

There you go.

matt
  • 515,959
  • 87
  • 875
  • 1,141