License MIT
Platforms ios 8.0

STNotifications: Strongly Typed Notifications for Objective C

Build status
Code coverage status

STNotifications is Objective-C library for Strongly Typed Notifications


  • [x] Strongly typed payload (using safe api around Objective-C lightweight generics)
  • [x] Makes sure only one NSNotificationName exists for Notification and Observer
  • [x] You have pointer to sender from recieved notification!
  • [x] Interoperable with Swift!
  • [x] Autounsubscribtion on NotificationToken deallocation!


Create factory method

#import <STNotifications/STNotifications.h>
@class Alert;

@interface STNotificationFactory (YourCustomNotifications)
+ (STNotificationFactory<Payload *> *)payloadFactory;

@implementation STNotificationFactory (YourCustomNotifications)
+ (STNotificationFactory<Payload *> *)payloadFactory {
    return [STNotificationFactory factoryWithNotificationName:@"Notification payload"];

or your own subclass:

#import <STNotifications/STNotifications.h>
#import "Alert.h"

@interface AlertNotificationFactory : STNotificationFactory <Alert *>
- (instancetype)init;
+ (instancetype)factory;

@implementation AlertNotificationFactory

- (instancetype)init {
    return self = [super initWithNotificationName:@"AlertNotification"];
+ (instancetype)factory {
    return [[AlertNotificationFactory alloc] init];

That’s it! Now your NotificationName and Payload Type can be no longer be messed up!

Start observing

Autocompletion will insert payload type you specified in factory same way as it’s in NSArray!
 STNotifications: Strongly Typed Notifications for Objective C

  @property (strong, nonatomic) STNotificationToken *token; // < ---- Auto Unsubscription on deallocation!
  let factory = [AlertNotificationFactory new];
  let alertObserver = [factory makeObserverWithOnRecievedBlock:^(STNotification<Alert *> * _Nullable notification) {
    NSLog(@"%@", notification.payload.message);
    NSLog(@"%@", notification.sender);
  self.alertToken = [[NSNotificationCenter defaultCenter] stn_addNotificationObserver:alertObserver];

You can track down sender of notification!
STNotificationToken has autounsubscription feature on deallocation!

Post notification

You can no longer mess up payload type!
 STNotifications: Strongly Typed Notifications for Objective C

  var alert = [Alert new];
  alert.message = @"ALARM!!!";

  let alertFactory = [AlertNotificationFactory new];
  let alertNotification = [alertFactory makeNotificationWithPayload:alert sender:self];
  [[NSNotificationCenter defaultCenter] stn_postNotification:alertNotification];



target '<Your Target Name>' do
    pod 'STNotifications', '~>'


github "neisip/StronglyTypedNotifications"


STNotifications is released under the MIT license. See LICENSE for details.

Latest podspec

    "name": "STNotifications",
    "version": "",
    "summary": "Tiny library for Strongly Typed Notifications in Objective-C",
    "description": "Strongly typed notificatinos allow your Objective-C notifications to work in a safe manner, using light generics magics and little bit of architecture tricks!nBenefits:n1) Strongly typed payloadn2) NSNotification name won't be messed again!n3) Easy syntax for usen4) Interoperable with swift!n5) 100% Code Coverage!",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Alexander Kazartsev": "[email protected]"
    "platforms": {
        "ios": "8.0"
    "source": {
        "git": "",
        "tag": ""
    "source_files": [
    "exclude_files": "Classes/Exclude"

Pin It on Pinterest

Share This