https://github.com/devandsev/justsignals
Signals to replace NotificationCenter and delegates, nothing more
https://github.com/devandsev/justsignals
delegate ios macos notificationcenter reactive rx signal swift4
Last synced: about 2 months ago
JSON representation
Signals to replace NotificationCenter and delegates, nothing more
- Host: GitHub
- URL: https://github.com/devandsev/justsignals
- Owner: devandsev
- License: mit
- Created: 2018-02-23T12:27:52.000Z (about 7 years ago)
- Default Branch: develop
- Last Pushed: 2018-02-25T11:38:42.000Z (about 7 years ago)
- Last Synced: 2025-03-24T15:11:29.424Z (about 2 months ago)
- Topics: delegate, ios, macos, notificationcenter, reactive, rx, signal, swift4
- Language: Swift
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JustSignals
[](https://travis-ci.org/devandsev/JustSignals)
JustSignals is a type-safe alternative to NotificationCenter and delegates. Use it if you don't need binding and rx magic in your project, and just want to replace NotificationCenter with something more strict and safe. Otherwise take a look at [RxSwift](https://github.com/ReactiveX/RxSwift), [ReactiveCocoa](https://github.com/ReactiveCocoa/ReactiveCocoa) and [Bond](https://github.com/ReactiveKit/Bond).
## Installation
### [CocoaPods](https://guides.cocoapods.org/using/using-cocoapods.html)
```ruby
# Podfile
use_frameworks!target 'YOUR_TARGET_NAME' do
pod 'JustSignals'
end
```Replace `YOUR_TARGET_NAME` and then, in the `Podfile` directory, type:
```bash
$ pod install
```### [Carthage](https://github.com/Carthage/Carthage)
Add this to `Cartfile`
```
github "devandsev/JustSignals"
```In the `Cartfile` directory, type:
```bash
$ carthage update
```## Usage examples
Signal without any data:
```swift
let signal = Signal()
signal.subscribe(with: self) {
print("pong")
}signal.fire(())
```Signal with data:
```swift
let signal = Signal()
signal.subscribe(with: self) { data in
print(data)
}signal.fire(36)
```If you need to pass multiple values:
```swift
let signal = Signal<(Int, Float, String, Bool)>()
signal.subscribe(with: self) { data in
print(data)
}signal.fire((3, 2.2, "test", false))
```Subscription cancels automatically if the object that has been subscribed to the signal is deallocated, but if you need to unsubscribe early, use this:
```swift
signal.unsubscribe(self)
```
## LicenseThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.