CocoaPods trunk is moving to be read-only. Read more on the blog, there are 16 months to go.

Swignals 1.0.0

Swignals 1.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Nov 2016
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Joseph Neuman.



Swignals 1.0.0

Swignals

Swignals is an observable pattern system written entirely in Swift.

Installing

You can either drag all the files from the Source folder into your project, or install it using CocoaPods.

Example

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
    }
}

Authors

Acknowledgements

License

This project is licensed under the MIT License - see the LICENSE.md file for details