Latest 0.0.2
Homepage https://github.com/vlfm/Response
License MIT
Platforms ios 8.0, osx 10.10
Dependencies FunctionalInterfaces
Authors

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 {
        //
    }
}

Latest podspec

{
    "name": "Response",
    "version": "0.0.2",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "summary": "Response",
    "homepage": "https://github.com/vlfm/Response",
    "authors": {
        "Valery Fomenko": "[email protected]"
    },
    "source": {
        "git": "https://github.com/vlfm/Response.git",
        "tag": "0.0.2"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.10"
    },
    "dependencies": {
        "FunctionalInterfaces": [
            "0.0.1"
        ]
    },
    "source_files": "Source/**/*.swift",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This