NSNotification concept - what part of the code goes there?

Part of me thinks I understand the concept of NSNotification. This is a centralized broadcast notification system with string notifications. A message on one side, observe on one or more other sides and act accordingly. The other part of me though, the part that needs to write the code gets confused every time I need a notification. What part of the code is included in the header / implementation, which files actually do the monitoring, and how do I keep it in a mess? Time to straighten it out, help me check these assumptions? I'm pretty sure before number 4, but number 5 gets into the jackpot of confusion.


  • NSNotifications are created using [NSNotification defaultCenter], does not highlight / do not run NSNotification. Correctly?
  • The entity performing postNofification function always passes selfin posting key: [[NSNotificationCenter defaultCenter] postNotificationName:@"note name" object:self]. Correctly?
  • Bankruptcy events exist in other languages, but not in Objective-C with NSNotification. You do not send notifications, you make the notification name specific enough for global broadcasting. Correctly?
  • If you still want to send the notification sent by object A, you observe it in B, process it, and publish a new, more specific notification for object C for observation. For instance. @"MenuItemTapped"A to B and @"NavigateTo"B to C. Correct?
  • The notification name is NSString. Since both the poster and the observer want to avoid typos, we store the NSString constant in the [extern const | define | class | none of the above]. Could you help me choose one?
    • - NotificationNames.h, extern NSString *const NOTE_NAME. .
    • NSNotification ( XCode ), Event AS3, -w481 > -ish. , [super init] NSNotification, - .
    • - #import. , / ?
+3
2

. 1-3, , .

  • NSNotification.
  • "" "" , , - , " " - , . .
  • "" . Cocoa ; //, "" " " . , , / . .
  • , -, , , . Cocoa extern NSString *const UIKeyboardDidShowNotification. - .

# 4 . , . . "MenuItemTapped" - , , "NavigateTo" , , - -. , , ( ) , , . , , , . Cocoa " , ", , ", , ". ?

, , re: # 4 - , , , , , .

+4
  • NSNotification, . postNotificationName:object: - , , .

  • . - , , , , , self.

  • - . .

  • - . , .

  • Externs .

+2

Source: https://habr.com/ru/post/1787161/


All Articles