Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Add section on NSNotification names #20

Closed
jacobvanorder opened this issue Aug 3, 2013 · 3 comments
Closed

Add section on NSNotification names #20

jacobvanorder opened this issue Aug 3, 2013 · 3 comments

Comments

@jacobvanorder
Copy link
Contributor

Perhaps how NYTimes team handles NSNotification names.

@chrisladd
Copy link
Contributor

@jacobvanorder currently, we store them all like this:

//  NYTNotification.h
extern NSString * const NYTBreakingNewsReceivedNotification;

. . .

//  NYTNotification.m
NSString * const NYTBreakingNewsReceivedNotification        = @"NYTBreakingNewsReceivedNotification";

Any thoughts / suggestions from the group on how we might?

@chrismaddern
Copy link

Notification names are constants so should follow the constants section styling.

As for where to store them.. I prefer exporting the notification name in the header of the related functionality. That way they're available wherever you need them but you don't get every token available in every file.

e.g.

// VENFeedUpdateOperation.h
extern NSString * const VENFeedUpdateCompletedNotification;

@interface VENFeedUpdateOperation
- (id) initWithVisibilityType:(VENVisibilityType *)visibility;
...
@end
// VENFeedViewController.m
#import "VENFeedUpdateOperation.h"

...

VENFeedUpdateOperation *updateOperation = [[VENFeedUpdateOperation alloc] initWithVisibilityType:currentVisibility];
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(feedUpdateCompleted:) name:VENFeedUpdateCompletedNotification object:updateOperation];

@jacobvanorder
Copy link
Contributor Author

I was just curious as if the NYT team uses certain prefixes or has any special rules but if they follow in a way to discern in other places in the code that this is a notification constant or not. It seems that a suffix is used in each one to give that indication. Again, I was just curious.

I tend to side with @chrismaddern on the fact that they should be kept with the related files in that if a particular feature and corresponding files are removed, so goes the cruft of all of the notification constants. I can see the side, though, of having all your constants in one place so you know where to add/remove them when need be or if two features share a notification, there's a neutral place for it.

@ashott ashott closed this as completed May 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants