Showing posts with label snippet. Show all posts
Showing posts with label snippet. Show all posts

Saturday, August 24, 2019

Snippet Code: NSNotification Register and Post


// Register
[[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(paintColorSelected:)
                                                 name:@"PaintColorSelected"
                                               object:nil];



// Post notification (normally in another ViewController
[[NSNotificationCenter defaultCenter] postNotificationName:@"PaintColorSelected" object:paintSelected.paintName];


Wednesday, March 2, 2016

Code Snippet: AppDelegate Constant

Useful to have to simplify your code if you use many appdelegates references. Of course, you need to import AppDelegate header in each of the main file you want to use this constant.


#import "AppDelegate.h"

#define MY_APPDELEGATE ((AppDelegate*)[UIApplication sharedApplication].delegate)