Search code examples
macosnstextviewnsnotifications

How to find NSNotification object type?


I am using NSNotification for my textView but this delegate method is also called for my textField click. So, how can i find out the object type of NSNotification???

Currently i am using:

MyTextView *text = (MyTextView *)[aNotification object];

here MyTextView is a class to refer textView. So, how can i differentiate the object type of NSNotification.

Please guide me. Thanks


Solution

  • I would not recommend doing this. Create two separate methods for each action/notification with different names clearly stating what they are handling.

    Anyway, what you're asking for is done like this

    if ([[aNotification object] isKindOfClass:[MyTextView class]])
    { treat it like MyTextView }
    

    I'm not sure what you mean with textField click, but it seems you may also need this

    if ([aNotification isKindOfClass:[NSNotification class]])
    {...}