Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Commit

Permalink
Release 0.2.3-objc NSNull fix and returning the Kommand on execute.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Rupérez committed Feb 27, 2017
1 parent 3fb1c2f commit 62d1028
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Kommander.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 3VW789WSMP;
DYLIB_COMPATIBILITY_VERSION = 0.2.0;
DYLIB_CURRENT_VERSION = 0.2.2;
DYLIB_CURRENT_VERSION = 0.2.3;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Kommander/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -370,7 +370,7 @@
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 3VW789WSMP;
DYLIB_COMPATIBILITY_VERSION = 0.2.0;
DYLIB_CURRENT_VERSION = 0.2.2;
DYLIB_CURRENT_VERSION = 0.2.3;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Kommander/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand Down
2 changes: 1 addition & 1 deletion Kommander/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.2.2</string>
<string>0.2.3</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
24 changes: 10 additions & 14 deletions Kommander/Kommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
import Foundation

@objc public protocol KommandProtocol {
init(deliverer: Dispatcher, executor: Dispatcher, block: @escaping () -> Any)
func onSuccess(block: @escaping (_ result: Any) -> Void) -> KommandProtocol
func onError(block: @escaping (_ error: Error) -> Void) -> KommandProtocol
func execute()
func onSuccess(block: @escaping (_ result: Any?) -> Void) -> KommandProtocol
func onError(block: @escaping (_ error: Error?) -> Void) -> KommandProtocol
func execute() -> KommandProtocol
func cancel()
}

open class Kommand<T>: KommandProtocol {

public typealias ActionBlock = () throws -> T
public typealias SuccessBlock = (_ result: T) -> Void
public typealias ErrorBlock = (_ error: Error) -> Void
public typealias ActionBlock = () throws -> T?
public typealias SuccessBlock = (_ result: T?) -> Void
public typealias ErrorBlock = (_ error: Error?) -> Void

private final let deliverer: Dispatcher
private final let executor: Dispatcher
Expand All @@ -35,16 +34,12 @@ open class Kommand<T>: KommandProtocol {
self.actionBlock = actionBlock
}

public convenience required init(deliverer: Dispatcher, executor: Dispatcher, block: @escaping () -> Any) {
self.init(deliverer: deliverer, executor: executor, actionBlock: { return block() as! T })
}

open func onSuccess(_ onSuccess: @escaping SuccessBlock) -> Self {
self.successBlock = onSuccess
return self
}

open func onSuccess(block: @escaping (Any) -> Void) -> KommandProtocol {
open func onSuccess(block: @escaping (Any?) -> Void) -> KommandProtocol {
return onSuccess(block)
}

Expand All @@ -53,11 +48,11 @@ open class Kommand<T>: KommandProtocol {
return self
}

open func onError(block: @escaping (Error) -> Void) -> KommandProtocol {
open func onError(block: @escaping (Error?) -> Void) -> KommandProtocol {
return onError(block)
}

open func execute() {
open func execute() -> KommandProtocol {
action = executor.execute {
do {
let result = try self.actionBlock()
Expand All @@ -70,6 +65,7 @@ open class Kommand<T>: KommandProtocol {
}
}
}
return self
}

open func cancel() {
Expand Down
2 changes: 1 addition & 1 deletion Kommander/Kommander.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import Foundation
executor = Dispatcher(label: name, qos: qos, attributes: attributes, autoreleaseFrequency: autoreleaseFrequency, target: target)
}

open func makeKommand<T>(_ actionBlock: @escaping () throws -> T) -> Kommand<T> {
open func makeKommand<T>(_ actionBlock: @escaping () throws -> T?) -> Kommand<T> {
return Kommand<T>(deliverer: deliverer, executor: executor, actionBlock: actionBlock)
}

Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
[![Platform](https://img.shields.io/cocoapods/p/Kommander.svg?style=flat)](http://cocoapods.org/pods/Kommander)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)


**Kommander** is a Swift library to manage the task execution in different threads. Through the definition a simple but powerful concept, [**Kommand**](https://en.wikipedia.org/wiki/Command_pattern).

Inspired on the Java library [**Kommander**](https://github.com/Wokdsem/Kommander) from [**Wokdsem**](https://github.com/Wokdsem).


![Kommander](https://raw.githubusercontent.com/intelygenz/Kommander-iOS/master/Kommander.png)

## Features
Expand All @@ -17,8 +21,8 @@
- [x] Cancel kommand or multiple kommands
- [x] Set kommand success block
- [x] Set kommand error block
- [x] Main threat dispatcher
- [x] Current threat dispatcher
- [x] Main thread dispatcher
- [x] Current thread dispatcher
- [x] Custom OperationQueue dispatcher
- [x] Custom DispatchQueue dispatcher
- [x] Execute single or multiple Operation
Expand All @@ -39,13 +43,13 @@ pod 'Kommander'
For Swift 2 compatibility use:

```ruby
pod 'Kommander', :git => 'https://github.com/intelygenz/Kommander-iOS.git', :tag => '0.2.2-swift2'
pod 'Kommander', :git => 'https://github.com/intelygenz/Kommander-iOS.git', :tag => '0.2.3-swift2'
```

For Objective-C compatibility use:

```ruby
pod 'Kommander', :git => 'https://github.com/intelygenz/Kommander-iOS.git', :tag => '0.2.2-objc'
pod 'Kommander', :git => 'https://github.com/intelygenz/Kommander-iOS.git', :tag => '0.2.3-objc'
```

#### Or you can install it with [Carthage](https://github.com/Carthage/Carthage):
Expand Down Expand Up @@ -77,12 +81,12 @@ Kommander().makeKommand { () -> Void in

## Authors

'Juan Trías' => '[email protected]', 'Roberto Estrada' => '[email protected]'

[alexruperez](https://github.com/alexruperez), [email protected]

[juantrias](https://github.com/juantrias), [email protected]
[RobertoEstrada](https://github.com/RobertoEstrada), [email protected]'

[RobertoEstrada](https://github.com/RobertoEstrada), [email protected]

## License

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

0 comments on commit 62d1028

Please sign in to comment.