Wormhole 1.0

Wormhole 1.0

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布上次发布2015年5月
SPM支持 SPM

nixzhu 维护。



Wormhole 不仅仅是 MMWormhole 的 Swift 版本,还提供了更好的 API 和使用逻辑。您可以单独移除任何监听器。

示例

在 WatchKit 扩展中传递信息

import Wormhole

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

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

在应用中创建一个监听器并监听消息

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")

现在可以轻松移除监听器

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

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

更多信息,请参阅演示。

许可证

Wormhole 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。