SwiftEvents is a lightweight, pure-Swift library for implementing events in iOS, macOS, watchOS, tvOS and Linux. It has
NotificationCenter (multiple subscribers to the event),
Delegation (one subscriber to the event) and
KVO (observing properties using the event) functionality in one simple, not verbose and type-safe API.
The purpose of SwiftEvents is to simplify and improve the communication between components in a modern Swift project.
In comparison with Cocoa mechanisms, SwiftEvents has the following features:
[x] Built-in solution for preventing retain cycles (no need to specify
[weak self]!), in order to always be protected from memory leaks
[x] Cancelable subscriptions: automatic removal of subscribers when they are deallocated, so you don't need to explicitly manage this
[ ] Thread-safety: subscribers can be registered on a different thread than notifications are sent on
[ ] Delayed and one-time sending notifications
[x] Ability to observe properties in any class or struct
[x] Easier to debug and test, since there is no dependency on UIKit
To install SwiftEvents using CocoaPods, add it to your
Swift Package Manager
To install SwiftEvents using the Swift Package Manager, add it to your
dependencies: [ .Package(url: "https://github.com/denissimon/SwiftEvents.git", majorVersion: 0) ]
Sources folder anywhere in your project.
Licensed under the MIT license