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

Release 1.1 with specific Error types. #15

Merged
merged 5 commits into from Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
# Release 1.1

- [x] Set kommand error closure specifying Error type.

# Release 1.0.2

- [x] Ready for Swift 4.2.
Expand Down
2 changes: 1 addition & 1 deletion Kommander.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Kommander'
s.version = '1.0.2'
s.version = '1.1'
s.summary = 'A command pattern implementation written in Swift'

s.homepage = 'https://github.com/intelygenz/Kommander-iOS'
Expand Down
30 changes: 15 additions & 15 deletions Kommander.xcodeproj/project.pbxproj
Expand Up @@ -590,56 +590,56 @@
TargetAttributes = {
815B58021E6573C700818819 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 3VW789WSMP;
DevelopmentTeam = Q6BEQCNWYM;
LastSwiftMigration = "";
ProvisioningStyle = Automatic;
};
815B58151E6573C800818819 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 3VW789WSMP;
DevelopmentTeam = Q6BEQCNWYM;
LastSwiftMigration = "";
ProvisioningStyle = Automatic;
TestTargetID = 815B58021E6573C700818819;
};
81925CC41E3A0FFC001701F3 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 3VW789WSMP;
DevelopmentTeam = Q6BEQCNWYM;
LastSwiftMigration = 1000;
ProvisioningStyle = Automatic;
};
81925CCD1E3A0FFC001701F3 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 3VW789WSMP;
DevelopmentTeam = Q6BEQCNWYM;
LastSwiftMigration = 1000;
ProvisioningStyle = Automatic;
};
819D155C1E76AEFB00BB1F07 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 3VW789WSMP;
DevelopmentTeam = Q6BEQCNWYM;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
81DBBAD61E768DB300EF01D8 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 3VW789WSMP;
DevelopmentTeam = Q6BEQCNWYM;
LastSwiftMigration = "";
ProvisioningStyle = Automatic;
};
81DBBAE31E768DE100EF01D8 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 3VW789WSMP;
DevelopmentTeam = Q6BEQCNWYM;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
81DBBB171E7691F300EF01D8 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 3VW789WSMP;
DevelopmentTeam = Q6BEQCNWYM;
LastSwiftMigration = "";
ProvisioningStyle = Automatic;
};
81DBBB231E7691F400EF01D8 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 3VW789WSMP;
DevelopmentTeam = Q6BEQCNWYM;
LastSwiftMigration = "";
ProvisioningStyle = Automatic;
};
Expand Down Expand Up @@ -990,9 +990,9 @@
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = "$(DYLIB_CURRENT_VERSION)";
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = 3VW789WSMP;
DYLIB_COMPATIBILITY_VERSION = 1.0.1;
DYLIB_CURRENT_VERSION = 1.0.2;
DEVELOPMENT_TEAM = Q6BEQCNWYM;
DYLIB_COMPATIBILITY_VERSION = 1.1;
DYLIB_CURRENT_VERSION = 1.1;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down Expand Up @@ -1064,9 +1064,9 @@
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = "$(DYLIB_CURRENT_VERSION)";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 3VW789WSMP;
DYLIB_COMPATIBILITY_VERSION = 1.0.1;
DYLIB_CURRENT_VERSION = 1.0.2;
DEVELOPMENT_TEAM = Q6BEQCNWYM;
DYLIB_COMPATIBILITY_VERSION = 1.1;
DYLIB_CURRENT_VERSION = 1.1;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down
Expand Up @@ -2,16 +2,4 @@
<Bucket
type = "4"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
scope = "0"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildSystemType</key>
<string>Latest</string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions Major/ViewController.swift
Expand Up @@ -59,8 +59,8 @@ class ViewController: UIViewController {
kommander.make {
sleep(self.sleepTime)
throw CocoaError(.featureUnsupported)
}.error { error in
print("Error: " + String(describing: error!))
}.error(CocoaError.self) {
print("Error: " + $0.localizedDescription)
}.execute()
}

Expand Down
17 changes: 15 additions & 2 deletions Package.swift
Expand Up @@ -2,6 +2,19 @@ import PackageDescription

let package = Package(
name: "Kommander",
products: [
.library(
name: "Kommander",
targets: ["Kommander"])
],
dependencies : [],
exclude: ["Major", "Major watchOS", "Major watchOS Extension", "MajorUITests", "KommanderTests"]
)
exclude: ["Major", "Major watchOS", "Major watchOS Extension", "MajorUITests", "KommanderTests"],
targets: [
.target(
name: "Kommander",
dependencies: []),
.testTarget(
name: "KommanderTests",
dependencies: []),
]
)
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -27,6 +27,7 @@ Inspired on the Java library [**Kommander**](https://github.com/Wokdsem/Kommande
- [x] Retry kommand or multiple kommands
- [x] Set kommand success closure
- [x] Set kommand error closure
- [x] Set kommand error closure specifying Error type
- [x] Main thread dispatcher
- [x] Current thread dispatcher
- [x] Custom OperationQueue dispatcher
Expand Down Expand Up @@ -116,6 +117,16 @@ Kommander().make {
}.execute()
```

##### Specify Error type:

```swift
Kommander().make {
throw MyError.error
}.error(MyError.self) { error in
// error is MyError type.
}.execute()
```

##### Retry after cancellation:

```swift
Expand Down
6 changes: 4 additions & 2 deletions Source/Dispatcher.swift
Expand Up @@ -96,15 +96,17 @@ open class Dispatcher {
}

public extension Array where Element: Operation {

/// Execute [Operation] instance collection in OperationQueue
public func execute(by operationQueue: OperationQueue, waitUntilFinished: Bool = false) {
public func execute(in operationQueue: OperationQueue, waitUntilFinished: Bool = false) {
operationQueue.addOperations(self, waitUntilFinished: waitUntilFinished)
}

/// Execute [Operation] instance collection in Dispatcher
public func execute(by dispatcher: Dispatcher, waitUntilFinished: Bool = false) {
public func execute(in dispatcher: Dispatcher, waitUntilFinished: Bool = false) {
dispatcher.execute(self, waitUntilFinished: waitUntilFinished)
}

}

private extension Dispatcher {
Expand Down
25 changes: 24 additions & 1 deletion Source/Kommand.swift
Expand Up @@ -107,12 +107,35 @@ open class Kommand<Result> {
return self
}

/// Specify Kommand<Result> error closure
@discardableResult open func error<Reason: Swift.Error>(_ type: Reason.Type, _ error: @escaping (_ error: Reason) -> Void) -> Self {
self.errorClosure = {
guard let reason = $0 as? Reason else {
assertionFailure("Unexpected error thrown. \(Reason.self) expected, \($0.debugDescription) thrown.")
return
}
error(reason)
}
return self
}

/// Specify Kommand<Result> retry closure
@discardableResult open func retry(_ retry: @escaping RetryClosure) -> Self {
self.retryClosure = retry
return self
}

/// Specify Kommand<Result> error closure
@discardableResult open func retry<Reason: Swift.Error>(_ type: Reason.Type, _ retry: @escaping (_ error: Reason?, _ executionCount: UInt) -> Bool) -> Self {
self.retryClosure = {
guard let reason = $0 as? Reason else {
return retry(nil, $1)
}
return retry(reason, $1)
}
return self
}

open var result: Result? {
guard case .succeeded(let result) = state else {
return nil
Expand All @@ -129,7 +152,7 @@ open class Kommand<Result> {

/// Execute Kommand<Result> after delay
@discardableResult open func execute(after delay: DispatchTimeInterval) -> Self {
executor?.execute(after: delay, closure: {
executor?.execute(after: delay, closure: {
self.execute()
})
return self
Expand Down
2 changes: 1 addition & 1 deletion Source/Kommander.swift
Expand Up @@ -59,7 +59,7 @@ open class Kommander {

/// Execute [Kommand<Result>] instances collection concurrently or sequentially after delay
open func execute<Result>(_ kommands: [Kommand<Result>], concurrent: Bool = true, waitUntilFinished: Bool = false, after delay: DispatchTimeInterval) {
executor.execute(after: delay) {
executor.execute(after: delay) {
self.execute(kommands, concurrent: concurrent, waitUntilFinished: waitUntilFinished)
}
}
Expand Down