CocoaPods trunk is moving to be read-only. Read more on the blog, there are 16 months to go.
TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Nov 2016 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Joseph Neuman.
Swignals is an observable pattern system written entirely in Swift.
You can either drag all the files from the Source folder into your project, or install it using CocoaPods.
Lets say we wanted to add a swignal to an AudioPlayer class whenever shuffle is set. It could look something like this:
typealias OnShuffleChangedSwignal = Swignal1Arg<Bool>
class AudioPlayer {
static let sharedInstance = AudioPlayer()
let onShuffleChanged = OnShuffleChangedSwignal()
var shuffle: Bool = false {
didSet {
onShuffleChanged.fire(shuffle)
}
}
}
Then to subscribe to that signal you’d do the following:
class ControlsViewController: UIViewController {
init() {
AudioPlayer.sharedInstance.onShuffleChanged.addObserver(self) { (observer, arg1) in
// note: you can rename the variables in the callback such as
// callback: { (weakSelf, shuffle) in
if let favoriteTracksDataSource = observer.tracksDataSource as? FavoriteTracksDataSource {
favoriteTracksDataSource.shuffle = arg1
favoriteTracksDataSource.refresh()
}
}
}
func updateViewBasedOnShuffle(shuffle: Bool) {
// do important things
}
}
This project is licensed under the MIT License - see the LICENSE.md file for details