Swift Event Center to create custom events and respond to them.
The idea was to build a simple event center from scratch to:
better understand how a notification/event center would work
have simple event manager for simple tasks
in pure Swift
and not use Apple’s Notification Center
The interesting thing about the process is that while building it, I got a deeper understanding of how Notification Center.
To make it easier for new comers, I decided to keep Apple’s way of naming things.
Note: EventCenter is not meant to be a full replacement of Notification Center. It is a simpler alternative (as in “simpler to use, but also simpler in terms of functionalities“) that should be good enough for simple projects.
Features
EventCenter allows you to:
add observer for Event.Name (a.k.a. Notification.Name)
specify a name for added observers so that they can be removed independently
remove all observers for a specific Event.Name
remove one observer with a specific name for a specific Event.Name
post events and pass object:Any? & userInfo:[AnyHashable:Any]?
specify priority for each observer (not implemented yet)
Installation
With SPM, add the following to the dependencies of your Package.swift
This project is based on great people’s ideas. The original idea was created by Stephen Haney. It was then improved by Robin Walter‘s Swift-Events. First I wanted to fork Robin’s repo but after spending a couple of hours on it, I decided to rewrite most of it. Original work from Stephen Haney & Robin Walter is under MIT.
Swift Event Center
About
Swift Event Center to create custom events and respond to them.
The idea was to build a simple event center from scratch to:
The interesting thing about the process is that while building it, I got a deeper understanding of how Notification Center.
To make it easier for new comers, I decided to keep Apple’s way of naming things.
Note: EventCenter is not meant to be a full replacement of Notification Center. It is a simpler alternative (as in “simpler to use, but also simpler in terms of functionalities“) that should be good enough for simple projects.
Features
EventCenter allows you to:
Event.Name
(a.k.a.Notification.Name
)Event.Name
name
for a specificEvent.Name
object:Any?
&userInfo:[AnyHashable:Any]?
Installation
With SPM, add the following to the dependencies of your
Package.swift
Usage
Event
is just atypealias
forNotification
.See docs, Examples & Tests for more information.
Authors
Made with ❤️ by:
License
Apache 2.0 @ Ladislas de Toldi
Original Work
This project is based on great people’s ideas. The original idea was created by Stephen Haney. It was then improved by Robin Walter‘s Swift-Events. First I wanted to fork Robin’s repo but after spending a couple of hours on it, I decided to rewrite most of it. Original work from Stephen Haney & Robin Walter is under MIT.