Karl von Moor
Karl von Moor

Reputation: 8614

Difference between NSNotification and NSEvent

I don't really understand the difference that cocoa makes between a notification and an event.

For instance I could have code like this:

-(void)mouseMoved:(NSEvent*)event { … }

but not

-(void)windowMoved:(NSEvent*)event { … }

For the second one I'd have to use NSNotification – why?

Upvotes: 1

Views: 764

Answers (1)

JustSid
JustSid

Reputation: 25318

The difference is, that NSEvent is used to encapsulate input events. Mouse down, key down etc. However, NSNotification is used to notify observers about a change of a state or an object (eg. when the network reachability changed, new data became available or that a window moved).

In your case: A window move isn't some kind of input, but a change of the windows position. Thus you get an NSNotification rather an NSEvent.

Upvotes: 6

Related Questions