Here’s a library submitted by CHEN Xian’an that provides another solution for automatically removing the observer for NotificationCenter without minimal code and without using method swizzling called CXAAutoRemovalNotification.

Here’s a a code example using CXAAutoRemovalNotification from the readme:

__weak typeof(self) weakSelf = self;
[self cxa_addObserverForName:UIContentSizeCategoryDidChangeNotification usingBlock:^(NSNotification *note) {
    [weakSelf.tableView reloadData];

You can find CXAAutoRemovalNotification on Github.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>