Created
November 10, 2020 15:04
-
-
Save ddaddy/d58b648dbe82a1c63fe23541cc1aad40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public protocol Journey { } | |
class CommsJourney: Journey { } | |
typealias Completion = (Result<[Journey]?, Error>) -> Void | |
typealias CommsCompletion = (Result<[CommsJourney]?, Error>) -> Void | |
class Comms { | |
func refreshTimes(completion: @escaping CommsCompletion) { | |
let array = [CommsJourney()] | |
completion(.success(array)) | |
} | |
} | |
/** | |
Completion block returns `Journey` protocol if successful | |
*/ | |
func refreshTimes(completion: @escaping Completion) { | |
// Passing the previous completion block fails to compile as signatures are different | |
// Comms().refreshTimes(completion: completion) | |
Comms().refreshTimes { (result) in | |
switch result { | |
case .success(let results): | |
// result is `CommsCompletion` yet returns perfectly fine | |
completion(.success(results)) | |
case .failure(let error): | |
completion(.failure(error)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment