{"id":19459969,"url":"https://github.com/julianalonso/usecase","last_synced_at":"2026-04-11T21:04:22.553Z","repository":{"id":56925456,"uuid":"81847468","full_name":"JulianAlonso/UseCase","owner":"JulianAlonso","description":"Use case base class to use .then and .catch","archived":false,"fork":false,"pushed_at":"2018-05-23T11:14:22.000Z","size":22,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T04:46:00.557Z","etag":null,"topics":["catch","ios","operationqueue","then","usecase"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JulianAlonso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-13T16:43:43.000Z","updated_at":"2018-05-23T11:14:15.000Z","dependencies_parsed_at":"2022-08-21T06:20:14.348Z","dependency_job_id":null,"html_url":"https://github.com/JulianAlonso/UseCase","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JulianAlonso%2FUseCase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JulianAlonso%2FUseCase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JulianAlonso%2FUseCase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JulianAlonso%2FUseCase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JulianAlonso","download_url":"https://codeload.github.com/JulianAlonso/UseCase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240664498,"owners_count":19837563,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["catch","ios","operationqueue","then","usecase"],"created_at":"2024-11-10T17:35:03.521Z","updated_at":"2026-04-11T21:04:22.526Z","avatar_url":"https://github.com/JulianAlonso.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"UseCase\n=======\n\nUse case library.\n\nUse case base class to use `.common` `.then` and `.catch` after execute.\n\nAny use case subclass must be initialized with a **OperationQueue**.\nThis class executes the code under an **Operation**, this means that UseCase can be suspended, or cancelled.\n\n## How use it.\nCreate a class or struct for the request and the response.\n\nThen create a subclass of UseCase\u003cRequest, Response\u003e with yours UseCaseRequest and UseCaseResponse.\nOverride 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.\n\n## Example:\n\n```swift\n\nstruct TestRequest {\n\n}\n\nstruct TestResponse {\n\n}\n\nenum TestError: Error {\n    case noRequest\n}\n\nfinal class TestUseCase: UseCase\u003cTestRequest, TestResponse\u003e {\n\n    override func main(request: TestRequest?, _ operation: UseCaseOperation\u003cTestRequest, TestResponse\u003e) {\n        DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + .milliseconds(600)) {\n            if request != nil {\n                operation.response = TestResponse()\n            } else {\n                operation.error = TestError.noRequest\n            }\n        }\n    }\n\n}\n\n//Using TestUseCase:\nuseCase.execute()\n.common {\n    print(\"Im finished.\")\n}\n.then { response in\n    print(\"With response \\(response)\")\n}\n.catch { (error) in\n    print(\"With error \\(error)\")\n}\n\n\n\n```\n\n## Contributing:\nIf you find and issue, please, write a test that reproduce it and notify me by github issues.\nIf you have some idea about how to improve it, fork it, write your code, test it and send me a pull request.\n\n## Developed by:\n\n[Julián Alonso](https://twitter.com/maisterJuli).\n\n## LICENSE:\nApache 2.0 license. See [`LICENSE`](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulianalonso%2Fusecase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjulianalonso%2Fusecase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulianalonso%2Fusecase/lists"}