NoticeObserveKit – A Swift Library That Simplifies Working With NSNotificationCenter

  •  
  •  
  •  
  •  
  •  

NoticeObserveKit is an open source Swift library submitted by Taiki Suzuki that provides a simpler syntax for working with NotificationCenter.

NoticeObserveKit provides a protocol which must be adhered to and then you can easily work with your observers.

This example of the readme demonstrations the creation of an observer pool with a couple of observers using NoticeObserveKit:

import UIKit
import NoticeObserveKit

class ViewController: UIViewController {
    private let searchBar = UISearchBar(frame: .zero)
    private var pool = NoticeObserverPool()

<pre><code>override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    navigationItem.titleView = searchBar

    configureObservers()
}

private func configureObservers() {
    UIKeyboardWillShow.observe { [unowned self] in
        print("UIKeyboard will show = \($0)")
    }.addObserverTo(pool)

    UIKeyboardWillHide.observe { [unowned self] in
        print("UIKeyboard will hide = \($0)")
    }.addObserverTo(pool)
}
</code></pre>

}

You can find NoticeObserveKit on Github here.

A nice library for working with NotificationCenter in Swift.


  •  
  •  
  •  
  •  
  •