{"id":22903111,"url":"https://github.com/dungntm58/cleanarchitectureusecase","last_synced_at":"2025-07-05T05:05:42.903Z","repository":{"id":260725612,"uuid":"882176305","full_name":"dungntm58/CleanArchitectureUseCase","owner":"dungntm58","description":"Use Case layer in Clean Architecture using Combine","archived":false,"fork":false,"pushed_at":"2025-03-02T18:09:04.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T07:21:19.322Z","etag":null,"topics":["clean-architecture","combine","combine-framework","ios","ios-swift","spm","swift","usecase"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dungntm58.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-02T04:37:03.000Z","updated_at":"2024-12-07T11:23:21.000Z","dependencies_parsed_at":"2024-11-02T05:22:22.584Z","dependency_job_id":"e6fb5249-44d5-42c0-8b40-d17b7ef1c2c6","html_url":"https://github.com/dungntm58/CleanArchitectureUseCase","commit_stats":null,"previous_names":["dungntm58/cleanarchitectureusecase"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dungntm58/CleanArchitectureUseCase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dungntm58%2FCleanArchitectureUseCase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dungntm58%2FCleanArchitectureUseCase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dungntm58%2FCleanArchitectureUseCase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dungntm58%2FCleanArchitectureUseCase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dungntm58","download_url":"https://codeload.github.com/dungntm58/CleanArchitectureUseCase/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dungntm58%2FCleanArchitectureUseCase/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263687150,"owners_count":23496088,"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":["clean-architecture","combine","combine-framework","ios","ios-swift","spm","swift","usecase"],"created_at":"2024-12-14T02:33:48.798Z","updated_at":"2025-07-05T05:05:42.878Z","avatar_url":"https://github.com/dungntm58.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Clean Architecture UseCase for iOS\n\nThis repository provides a reusable **UseCase** implementation for iOS projects, adhering to the principles of **Clean Architecture**. It includes an abstract `UseCase` protocol and concrete `UseCase` structs designed to handle **task retrying** and **activity tracking**.\n\n## Table of Contents\n\n- [Overview](#overview)\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [License](#license)\n\n---\n\n## Overview\n\nThis library is designed to simplify **Use Case** implementations in iOS projects. By encapsulating task-related logic, such as retrying failed operations and tracking ongoing activities, it enhances the modularity and maintainability of your app.\n\n### Key Concepts:\n- **UseCase Protocol**: A generic protocol for defining use cases with type safety.\n- **Task Retrying**: Implement robust retry mechanisms for tasks that may fail.\n- **Activity Tracking**: Monitor the active state of ongoing operations, useful for UI updates or background tasks.\n\nThis library is built with support for **Swift Package Manager (SPM)** to ensure seamless integration with iOS projects.\n\n---\n\n## Features\n\n- **Abstract UseCase Protocol**:  \n  A base protocol for defining reusable and type-safe use cases.\n\n- **Task Retrying**:  \n  Handle transient failures by implementing configurable retry logic.\n\n- **Activity Tracking**:  \n  Track and manage active tasks to streamline UI state updates (e.g., showing a loading spinner).\n\n- **SPM Support**:  \n  Easily add the library to your iOS project using **Swift Package Manager**.\n\n---\n\n## Installation\n\n### Swift Package Manager\n\nTo integrate this library into your project:\n\n1. Open your project in Xcode.\n2. Navigate to **File \u003e Add Packages...**.\n3. Enter the repository URL:  \n   ```\n   https://github.com/dungntm58/CleanArchitectureUseCase\n   ```\n4. Choose the desired version or branch, then add the package to your project.\n\n---\n\n## Usage\n\n### Defining a Custom UseCase\n\nTo create a new use case, conform to the `UseCase` protocol:\n\n```swift\nimport CleanArchitectureUseCase\n\nstruct MyUseCase: UseCase {\n    func execute(input: String) -\u003e Int {\n        input.count\n    }\n}\n\nenum MyError: Error {\n    case invalidLength\n}\n\nstruct MyCustomUseCase: ReactiveUseCase {\n    func execute(input: String) -\u003e some Publisher\u003cInt, MyError\u003e {\n        Future { promise in\n            if input.count \u003e 255 {\n                promise(.failure(.invalidLength))\n            } else {\n                promise(.success(input.count))\n            }\n        }\n    }\n}\n```\n\n### Retrying a Task\n\nUse the built-in retryable use case to handle task failures:\n\n```swift\nimport CleanArchitectureUseCase\n\nclass MyViewModel: UseCaseRetrySource {\n    @Published var isShowingErrorPopup: Bool = false\n\n    func retryEffect() -\u003e some Publisher\u003cBool, Never\u003e {\n        $isShowingErrorPopup\n    }\n}\n\nlet viewModel = MyViewModel()\nlet retryableUseCase = MyCustomUseCase().makeRetryable(retrySource: viewModel)\nlet result = retryableUseCase.execute(\"Hello, world!\")\nprint(result)\n```\n\n### Tracking Task Activities\n\nMonitor the state of ongoing tasks using the activity tracker:\n\n```swift\nimport CleanArchitectureUseCase\n\nclass MyViewModel: UseCaseTrackableSource, Trackable {\n    @Published var isLoading: Bool = false\n\n    func beginActivity() {\n        isLoading = true\n    }\n\n    func endActivity() {\n        isLoading = false\n    }\n}\n\nlet viewModel = MyViewModel()\nlet trackableUseCase = MyCustomUseCase().makeTrackable(viewModel)\nlet result = trackableUseCase.execute(\"Hello, world!\")\nprint(result)\n```\n\n---\n\n## Contributing\n\nContributions are welcome! If you’d like to improve this library:\n\n1. Fork the repository.\n2. Create a feature branch:\n   ```bash\n   git checkout -b feature/new-feature\n   ```\n3. Commit your changes:\n   ```bash\n   git commit -m \"Add new feature\"\n   ```\n4. Push to your fork:\n   ```bash\n   git push origin feature/new-feature\n   ```\n5. Open a pull request.\n\n---\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\nFeel free to open issues or discussions for any suggestions or questions. 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdungntm58%2Fcleanarchitectureusecase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdungntm58%2Fcleanarchitectureusecase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdungntm58%2Fcleanarchitectureusecase/lists"}