Get Updates By E-mail 

Article Written By:
Johann Dowa

NoticeObserveKit – A Swift Library That Simplifies Working With NSNotificationCenter

  • 11
  • 1
  •  
  •  
  •  

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.


  • 11
  • 1
  •  
  •  
  •  

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