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:
[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.
Original article: Open Source Library Providing Automatic NSNotificationCenter Observer Removal Without Swizzling
©2014 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.