Skip to content

Instantly share code, notes, and snippets.

@maxhuk
Created April 9, 2013 09:45
Show Gist options
  • Save maxhuk/5344469 to your computer and use it in GitHub Desktop.
Save maxhuk/5344469 to your computer and use it in GitHub Desktop.
Useful when sending notifications from a worker queue.
//
// NSNotificationCenter+GCD.h
//
// Created by Maksym Huk on 10/30/12.
// Copyright (c) 2012 Maksym Huk. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSNotificationCenter (GCD)
- (void)postNotificationOnMainQueueName:(NSString *)aName object:(id)anObject;
- (void)postNotificationOnMainQueueName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo;
@end
//
// NSNotificationCenter+GCD.m
//
// Created by Maksym Huk on 10/30/12.
// Copyright (c) 2012 Maksym Huk. All rights reserved.
//
#import "NSNotificationCenter+GCD.h"
@implementation NSNotificationCenter (GCD)
- (void)postNotificationOnMainQueueName:(NSString *)aName object:(id)anObject
{
dispatch_async(dispatch_get_main_queue(), ^{
[self postNotificationName:aName object:anObject];
});
}
- (void)postNotificationOnMainQueueName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo
{
dispatch_async(dispatch_get_main_queue(), ^{
[self postNotificationName:aName object:anObject userInfo:aUserInfo];
});
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment