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

Commit

Permalink
Swift 3 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
igzrobertoestrada committed Oct 5, 2016
1 parent d9439a3 commit ee67182
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 34 deletions.
3 changes: 3 additions & 0 deletions Example/Kommander.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
TargetAttributes = {
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0800;
TestTargetID = 607FACCF1AFB9204008FA782;
};
};
Expand Down Expand Up @@ -323,6 +324,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -338,6 +340,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion Example/Tests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Tests: XCTestCase {

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock() {
self.measure() {
// Put the code you want to measure the time of here.
}
}
Expand Down
9 changes: 4 additions & 5 deletions Kommander/Classes/GCDKommandExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

import Foundation

public class GCDKommandExecutor: KommandExecutor {
open class GCDKommandExecutor: KommandExecutor {

public init(){
}

public func execute(block: () -> Void) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) {

public func execute(_ block: @escaping () -> Void) {
DispatchQueue.global(qos: .userInitiated).async {
block()
}
}
}
}
30 changes: 15 additions & 15 deletions Kommander/Classes/Kommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,47 @@

import Foundation

public class Kommand<T> {
open class Kommand<T> {

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

private let action: ActionBlock
private var successBlock: SuccessBlock?
private var errorBlock: ErrorBlock?
fileprivate let action: ActionBlock
fileprivate var successBlock: SuccessBlock?
fileprivate var errorBlock: ErrorBlock?

private let executor: KommandExecutor
private let deliverer: KommandDeliverer
fileprivate let executor: KommandExecutor
fileprivate let deliverer: KommandDeliverer

internal init(action: ActionBlock, executor: KommandExecutor, deliverer: KommandDeliverer) {
internal init(action: @escaping ActionBlock, executor: KommandExecutor, deliverer: KommandDeliverer) {
self.action = action
self.executor = executor
self.deliverer = deliverer
}

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

public func onError(onError: ErrorBlock) -> Self {
open func onError(_ onError: @escaping ErrorBlock) -> Self {
self.errorBlock = onError
return self
}

public func execute() {
open func execute() {
executor.execute {
do {
let result = try self.action()
self.deliverer.deliver {
self.successBlock?(result: result)
self.successBlock?(result)
}
} catch let error {
self.deliverer.deliver {
self.errorBlock?(error: error)
self.errorBlock?(error)
}
}
}
}
}
}
4 changes: 2 additions & 2 deletions Kommander/Classes/KommandDeliverer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import Foundation

public protocol KommandDeliverer {

func deliver(block: () -> Void)
}
func deliver(_ block: @escaping () -> Void)
}
4 changes: 2 additions & 2 deletions Kommander/Classes/KommandExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import Foundation

public protocol KommandExecutor {

func execute(block: () -> Void)
}
func execute(_ block: @escaping() -> Void)
}
10 changes: 5 additions & 5 deletions Kommander/Classes/Kommander.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

import Foundation

public class Kommander {
open class Kommander {

private let executor: KommandExecutor
private let deliverer: KommandDeliverer
fileprivate let executor: KommandExecutor
fileprivate let deliverer: KommandDeliverer

public init(executor: KommandExecutor, deliverer: KommandDeliverer) {

self.executor = executor
self.deliverer = deliverer
}

public func makeKommand<T>(action: () throws -> T) -> Kommand<T> {
open func makeKommand<T>(_ action: @escaping () throws -> T) -> Kommand<T> {
return Kommand<T>(action: action, executor: executor, deliverer: deliverer)
}
}
}
8 changes: 4 additions & 4 deletions Kommander/Classes/MainQueueKommandDeliverer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

import Foundation

public class MainQueueKommandDeliverer: KommandDeliverer {
open class MainQueueKommandDeliverer: KommandDeliverer {

public init(){
}

public func deliver(block: () -> Void) {
dispatch_async(dispatch_get_main_queue()) {
public func deliver(_ block: @escaping () -> Void) {
DispatchQueue.main.async {
block()
}
}
}
}

0 comments on commit ee67182

Please sign in to comment.