Skip to content
NoticeObserveKit is type-safe NotificationCenter wrapper.
Branch: master
Clone or download
Latest commit 96d4ca3 Feb 16, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example extra sample files Feb 16, 2019
NoticeObserveKit.xcodeproj support multi os Feb 16, 2019
NoticeObserveKit.xcworkspace fix directory structures Feb 16, 2019
NoticeObserveKit fix availability Feb 16, 2019
NoticeObserveKitTests add test case Feb 16, 2019
.gitignore extra sample files Feb 16, 2019
.swift-version support swift4 Sep 25, 2017
LICENSE Initial Commit Dec 28, 2016
NoticeObserveKit.podspec update podspec Feb 16, 2019 support multi os Feb 16, 2019


Version License Carthage compatible Platform

NoticeObserveKit is type-safe NotificationCenter wrapper.

// .keyboardWillShow is a static property.
Notice.Center.default.observe(name: .keyboardWillShow) { keyboardInfo in
    // In this case, keyboardInfo is UIKeyboardInfo type.
    // It is inferred from a generic parameter of Notice.Name<Value>.
// pool is Notice.ObserverPool.
// If pool is released, Notice.Observes are automatically removed.
.invalidated(by: pool)


First of all, you need to implement Notice.Name<T> like this. T is type of value in notification.userInfo.

extension Notice.Names {
    static let keyboardWillShow = Notice.Name<UIKeyboardInfo>(UIResponder.keyboardWillShowNotification)

If you define custom object, you need to implement that with NoticeUserInfoDecodable protocol. To confirm this protocol, you must implement init?(info: [AnyHashable : Any]) and func dictionaryRepresentation() -> [AnyHashable : Any].

struct UIKeyboardInfo: NoticeUserInfoDecodable {
    let frame: CGRect
    let animationDuration: TimeInterval
    let animationCurve: UIViewAnimationOptions

    init?(info: [AnyHashable : Any]) {
            let frame = (info[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
            let duration = info[UIKeyboardAnimationDurationUserInfoKey] as? TimeInterval,
            let curve = info[UIKeyboardAnimationCurveUserInfoKey] as? UInt
        else {
            return nil
        self.frame = frame
        self.animationDuration = duration
        self.animationCurve = UIViewAnimationOptions(rawValue: curve)

Usage for under v0.4.0 is documents/v0_4_0.


If you can post custom Notification like this.

extension Notice.Names {
    static let navigationControllerDidShow = Notice.Name<NavigationControllerContent>(name: "navigationControllerDidShow")

let content = NavigationControllerContent(viewController: viewController, animated: animated) .navigationControllerDidShow, value: content)

You can invalidate manually like this.

let observer = Notice.Center.default.observe(name: .keyboardWillShow) { keyboardInfo in

You can use vi NotificationCenter.

NotificationCenter.default.nok.observe(name: .keyboardWillShow) { keyboardInfo in
.invalidated(by: pool)


import UIKit
import NoticeObserveKit

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

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


    private func configureObservers() {
        Notice.Center.default.observe(name: .keyboardWillShow) {
            print("UIKeyboard will show = \($0)")
        }.invalidated(by: pool)

        Notice.Center.default.observe(name: .keyboardWillHide) {
            print("UIKeyboard will hide = \($0)")
        }.invalidated(by: pool)


  • Swift 4.2
  • Xcode 10.1 or greater
  • iOS 10.0 or greater
  • tvOS 10.0 or greater
  • macOS 10.10 or greater
  • watchOS 3.0 or greater



NoticeObserveKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "NoticeObserveKit"


If you’re using Carthage, simply add NoticeObserveKit to your Cartfile:

github "marty-suzuki/NoticeObserveKit"

Make sure to add NoticeObserveKit.framework to "Linked Frameworks and Libraries" and "copy-frameworks" Build Phases.




NoticeObserveKit is available under the MIT license. See the LICENSE file for more info.

You can’t perform that action at this time.