CocoaPods trunk is moving to be read-only. Read more on the blog, there are 17 months to go.
TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Aug 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✓ |
Maintained by Valery Fomenko.
Asyncronous callbacks conflict with standard Swift error handling.
Response helps to fix this.
Classical interfaces using completion handlers look like this:
protocol MessageService {
func get(id: String, completionHandler: (Message?, Error?) -> Void)
}
let messages: MessageService = //
messages.get(id: "123") { message, error in
// implicit convention that there are two valid combinations
// (message, nil)
// (nil, error)
// Swift error handling is not applicable
if let message = message {
//
} else if let error = error {
//
} else {
// ??
}
}
Same example using Response:
import Response
protocol MessageService {
func get(id: String, responseHandler: Response<Message>.Handler)
}
let messages: MessageService = //
messages.get(id: "123") { response in
do {
let message = try response.result()
//
} catch {
//
}
}