Get Updates By E-mail 

Article Written By:
Johann Dowa

Open Source Library Providing Automatic NSNotificationCenter Observer Removal Without Swizzling

  •  
  •  
  •  
  •  
  •  

When using the observer pattern, bugs often occur when an observer is not removed and previously I mentioned a library that utilizes swizzing to auto-remove your NSNotificationCenter observers.

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 here.

A nice library for reducing boilerplate code when using NotificationCenter.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments