Wormhole 1.0

Wormhole 1.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release May 2015
SPMSupports SPM

Maintained by nixzhu.



Wormhole is not just a Swift port of MMWormhole but with better API and use logic. You can remove any a listener from it separately.

Example

In WatchKit extension, passing a message:

import Wormhole

let wormhole = Wormhole(appGroupIdentifier: "group.com.nixWork.Wormhole", messageDirectoryName: "Wormhole")

wormhole.passMessage(NSNumber(bool: lightState), withIdentifier: "lightState")

In App, make a listener and listen a message:

import Wormhole

let wormhole = Wormhole(appGroupIdentifier: "group.com.nixWork.Wormhole", messageDirectoryName: "Wormhole")

lazy var lightStateListener: Wormhole.Listener = {
    let action: Wormhole.Listener.Action = { [unowned self] message in
        if let lightState = message as? NSNumber {
            self.lightStateLabel.text = lightState.boolValue ? "Light On" : "Light Off"
        }
    }

    let listener = Wormhole.Listener(name: "lightStateLabel", action: action)

    return listener
    }()

wormhole.bindListener(lightStateListener, forMessageWithIdentifier: "lightState")

Now easy to remove a listener:

wormhole.removeListener(lightStateListener, forMessageWithIdentifier: "lightState")

or

wormhole.removeListenerByName("lightStateLabel", forMessageWithIdentifier: "lightState")

For more information, see the demo.

License

Wormhole is available under the MIT license. See the LICENSE file for more info.