Latest 1.0.0
Homepage https://github.com/finder39/Swignals
License MIT
Platforms ios 8.0, osx 10.9, tvos 9.0, watchos 2.0
Authors

Swignals is an observable pattern system written entirely in Swift.

CocoaPods Compatible
Platform

Installing

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

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 0.39.0+ is required to build Swignals.

To integrate Swignals into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Swignals', '~> 1.0'
end

Then, run the following command:

$ pod install

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

Latest podspec

{
    "name": "Swignals",
    "version": "1.0.0",
    "summary": "Swignals is an observable pattern system written entirely in Swift.",
    "homepage": "https://github.com/finder39/Swignals",
    "license": {
        "type": "MIT",
        "file": "LICENSE.md"
    },
    "authors": {
        "Joseph Neuman": "[email protected]"
    },
    "source": {
        "git": "https://github.com/finder39/Swignals.git",
        "tag": "1.0.0"
    },
    "social_media_url": "https://twitter.com/finder39",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "source_files": "Source/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This