Latest 1.0.4
Homepage https://github.com/julianalonso/UseCase
License MIT
Platforms ios 9.0, requires ARC
Authors

Use case library.

Use case base class to use .common .then and .catch after execute.

Any use case subclass must be initialized with a OperationQueue.
This class executes the code under an Operation, this means that UseCase can be suspended, or cancelled.

How use it.

Create a class or struct for the request and the response.

Then create a subclass of UseCase<Request, Response> with yours UseCaseRequest and UseCaseResponse.
Override the main method, this receives a operation object. When your code finish, set operation.response or operation.error to end the execution of your code.

Example:


struct TestRequest {

}

struct TestResponse {

}

enum TestError: Error {
    case noRequest
}

final class TestUseCase: UseCase<TestRequest, TestResponse> {

    override func main(request: TestRequest?, _ operation: UseCaseOperation<TestRequest, TestResponse>) {
        DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + .milliseconds(600)) {
            if request != nil {
                operation.response = TestResponse()
            } else {
                operation.error = TestError.noRequest
            }
        }
    }

}

//Using TestUseCase:
useCase.execute()
.common {
    print("Im finished.")
}
.then { response in
    print("With response (response)")
}
.catch { (error) in
    print("With error (error)")
}

Contributing:

If you find and issue, please, write a test that reproduce it and notify me by github issues.
If you have some idea about how to improve it, fork it, write your code, test it and send me a pull request.

Developed by:

Julián Alonso.

LICENSE:

Apache 2.0 license. See LICENSE file for details

Latest podspec

{
    "name": "UseCase",
    "version": "1.0.4",
    "summary": "UseCase Base class to use .then, .catch",
    "platforms": {
        "ios": "9.0"
    },
    "description": "UseCase base class is designed to use .then and .catch when use case is finished.nIt use apple operations framework to execute your use case `main` code.",
    "homepage": "https://github.com/julianalonso/UseCase",
    "license": "MIT",
    "authors": {
        "Julian Alonso": "[email protected]"
    },
    "source": {
        "git": "https://github.com/julianalonso/UseCase.git",
        "tag": "1.0.4"
    },
    "social_media_url": "https://twitter.com/MaisterJuli",
    "requires_arc": true,
    "source_files": "Sources/**/*.swift",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This