Latest 0.0.7
Homepage https://github.com/Ekhoo/CommandBus
License MIT
Platforms ios 8.0, requires ARC
Dependencies SwiftyJSON
Authors

CommandBus

Version
License
Platform


![](https://img.shields.io/badge/Swift 2-compatible-4BC51D.svg?style=flat-square)

A light weight Command Bus implementation written in Swift

CommandBus?

The idea of a command bus is that you create command objects that represent what you want your application to do. Then, you toss it into the bus and the bus makes sure that the command object gets to where it needs to go.

So, the command goes in -> the bus hands it off to a handler -> and then the handler actually does the job. The command essentially represents a method call to your application layer.

You can have more informations here.

Installation

CocoaPods

CommandBus is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "CommandBus", '~> 0.0.7'

Usage

  • First, you have to create a json mapping file in order to associate yours Commands with their handler:
{
    "{CommandNameA}": "{CommandHandlerNameA}",
    "{CommandNameB}": "{CommandHandlerNameB}",
    "{CommandNameC}": "{CommandHandlerNameC}"
}
  • Then you can create your Command and inject it to the bus:
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        /*** Register to the Command event ***/
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "onCommandHandled:", name:"COMMAND_DONE", object: nil)

        /*** Create the CommandBus ***/
        let commandBus: CommandBus = CommandBus(configurationFileName: "configuration")!

        /*** Create your own Command ***/
        let customCommand: CustomCommand = CustomCommand()

        /*** Send your command to the CommandBus with your event name ***/
        commandBus.handle(command: customCommand, commandHandledEvent: "COMMAND_DONE")
    }

    func onCommandHandled(notification: NSNotification) {
        /*** This method is called when the CommandHandler have done ***/
        print("Command Handled: (notification.object!)")
    }
}

You can also see the Example project.

Author

Ekhoo:

License

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

Latest podspec

{
    "name": "CommandBus",
    "version": "0.0.7",
    "summary": "CommandBus is a light weight Command Bus implementation written in Swift",
    "description": "CommandBus is a light weight Command Bus implementation written in Swift. You can use it in order to facilitate your Command pattern implementation. It's also recommanded to use this pattern in a Domain Driven Design achitecture.",
    "homepage": "https://github.com/Ekhoo/CommandBus",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Lucas Ortis": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/Ekhoo/CommandBus.git",
        "tag": "0.0.7"
    },
    "source_files": "Source/*.swift",
    "requires_arc": true,
    "dependencies": {
        "SwiftyJSON": [
            "~> 2.3.0"
        ]
    }
}

Pin It on Pinterest

Share This