emitter-kit v5.2.2
A replacement for NSNotificationCenter#addObserver
and NSObject#addObserver
that is type-safe and not verbose.
Targeting
A target allows you to associate a specific AnyObject
with an emit
call. This is useful when emitting events associated with classes you can't add properties to (like UIView
).
When calling emit
with a target, you must also call on
or once
with the same target in order to receive the emitted event.
NSNotification
The Notifier
class helps when you are forced to use NSNotificationCenter
(for example, if you want to know when the keyboard has appeared).
Key-Value Observation (KVO)
Thread Safety
⚠️ None of the classes in EmitterKit are thread-safe!
The following actions must be done on the same thread, or you need manual locking:
- Emit an event
- Add/remove a listener
- Set the
isListening
property of a listener
v5.2.2 changelog
- Fixed protocol casting (#60)
v5.2.1 changelog
- Fix Carthage compatibility for non iOS platforms
v5.2.0 changelog
- Added the
Event.getListeners
method - Listeners are now always called in the order they were added
- Event
.emit() can be called without an argument - Carthage support has been improved
v5.1.0 changelog
-
The
NotificationListener
class now takes aNotification
instead of anNSDictionary
. -
A
NotificationListener
without a target will now receive everyNotification
with its name, regardless of the value ofnotif.object
.
v5.0.0 changelog
-
Swift 3.0 + Xcode 8.0 beta 6 support
-
The
Signal
class was removed. (useEvent<Void>
instead) -
The
Emitter
abstract class was removed. -
The
EmitterListener
class was renamedEventListener<T>
. -
The
Event<T>
class no longer has a superclass. -
The
Notification
class was renamedNotifier
(to prevent collision withFoundation.Notification
). -
The
on
andonce
methods ofEvent<T>
now return anEventListener<T>
(instead of just aListener
) -
The
on
andonce
methods ofNotifier
now return anNotificationListener
(instead of just aListener
) -
The
on
andonce
methods ofNSObject
now return anChangeListener<T>
(instead of just aListener
) -
The
keyPath
,options
, andobject
properties ofChangeListener<T>
are now public. -
A
listenerCount: Int
computed property was added to theEvent<T>
class. -
An
event: Event<T>
property was added to theEventListener<T>
class.
The changelog for older versions can be found here.