Latest 0.9
License MIT
Platforms ios 8.0


Allows to send arbitrary data between parts of an application that are not directly connected.
Normally, you would do so by sending a Notification with NotificationCenter, attaching the object you are sending to userInfo.
This library does exactly that; with sugar:

  • no need to define a notificationName
  • no need to unsubscribe; observer will be unsubscribed from NotificationCenter automatically upon deinit
  • you still have ability to unsubscribe at any point
  • clear syntax.
pod 'EventNotification'

Say, you have

struct A {
    let string: String

To send an instance of A to all interested observers,

extension A: Event {}

class SomeEventObserver: EventObserver {
    let eventToken = EventToken()

    func startObservingA() {
        handleEvent(A.self) { [weak self] a in

    func stopObservingA() {

    func stopObservingAll() {

let a = A(string: "hfgjhk m,jkj fghjv")

let eventToken = EventToken() is the only requirement for a observer class.

A not-uncommon case is, a observer class has no intent to unsubscribe from observing events (it will be unsubscribed automatically on deinit).
It the observer class may conform to DefaultEventObserver, which provides default implementation of var eventToken.

class OtherEventObserver: DefaultEventObserver {

    func startObservingA() {
        handleEvent(A.self) { [weak self] a in


The library includes implementaion of keyboard events

KeyboardDidShowEvent, KeyboardWillShowEvent, KeyboardWillHideEvent, KeyboardWillChangeFrameEvent

class ViewControllerController: UIViewController, KeyboardEventObserver {

    let eventToken = EventToken()

    override func viewDidAppear(_ animated: Bool) {

        onKeyboardWillAppear { [weak self] frame in
            var contentInsets: UIEdgeInsets = .zero
            contentInsets.bottom = frame.height
            self?.tableView.contentInset = contentInsets
            self?.tableView.scrollIndicatorInsets = contentInsets

        onKeyboardDissappear { [weak self] in
            self?.tableView.contentInset = .zero
            self?.tableView.setContentOffset(.zero, animated: true)

        onKeyboardFrameChanged { [weak self] frame in
            // new frame

    override func viewDidDisappear(_ animated: Bool) {


        // or,

Latest podspec

    "name": "EventNotification",
    "version": "0.9",
    "summary": "Typed notification events",
    "description": "Send arbitrary data between parts of an application that are not directly connected.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": "ark dan",
    "platforms": {
        "ios": "8.0"
    "swift_version": "4.0",
    "source": {
        "git": "",
        "tag": "0.9"
    "source_files": "EventNotification/*.{h,m,swift}"

Pin It on Pinterest

Share This