{"id":15170572,"url":"https://github.com/mmmagiccoder/swiftnet","last_synced_at":"2026-02-14T22:02:20.462Z","repository":{"id":254310067,"uuid":"846145728","full_name":"MMMagicCoder/SwiftNet","owner":"MMMagicCoder","description":"💻 A Swift package for flexible networking in SwiftUI, offering JSON and data fetching, file uploading, and downloading using Escaping Closures, Combine, and async-await.","archived":false,"fork":false,"pushed_at":"2024-09-18T19:10:58.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-17T01:41:15.265Z","etag":null,"topics":["async-await","combine","downloading","escaping","escapingclosures","fetching","ios","json","library","network","networking","swift","swift-package-manager","swiftui","uploading","urlsession","xcode"],"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/MMMagicCoder.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-08-22T16:08:42.000Z","updated_at":"2024-09-20T15:20:40.000Z","dependencies_parsed_at":"2024-09-05T16:40:45.316Z","dependency_job_id":"f67b4c67-5e7f-4e0d-a3ff-8aa85fe4703b","html_url":"https://github.com/MMMagicCoder/SwiftNet","commit_stats":{"total_commits":31,"total_committers":1,"mean_commits":31.0,"dds":0.0,"last_synced_commit":"44c6365b6b78ae4df39b0a3ff16044bdcb5dddf7"},"previous_names":["mmmagiccoder/swiftnet"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MMMagicCoder%2FSwiftNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MMMagicCoder%2FSwiftNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MMMagicCoder%2FSwiftNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MMMagicCoder%2FSwiftNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MMMagicCoder","download_url":"https://codeload.github.com/MMMagicCoder/SwiftNet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254095007,"owners_count":22013675,"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":["async-await","combine","downloading","escaping","escapingclosures","fetching","ios","json","library","network","networking","swift","swift-package-manager","swiftui","uploading","urlsession","xcode"],"created_at":"2024-09-27T08:04:09.302Z","updated_at":"2025-10-06T19:06:25.914Z","avatar_url":"https://github.com/MMMagicCoder.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftNet\n\n ![](https://img.shields.io/badge/platform-iOS-d3d3d3) ![](https://img.shields.io/badge/iOS-13.0%2B-43A6C6) ![](https://img.shields.io/badge/Swift-5-F86F15)\n\n`SwiftNet` is a Swift package designed to simplify networking operations in `SwiftUI`. It offers three flexible approaches for fetching, downloading, and uploading data or files using `Escaping Closures`, `Combine`, and `async-await` techniques, allowing you to choose the method that best suits your project requirements.\n\n## Table of contents\n   - [Requirements](#requirements)\n   - [Installation](#installation)\n     - [Swift Package Manager (SPM)](#spm)\n   - [Usage](#usage)\n     - [Fetching Data](#fetching)\n     - [Downloading Files](#downloading)\n     - [uploading Data](#uploading)\n   - [Contribution](#contribution)\n   - [License](#license)\n\n## Requirements\n\u003ca id=\"requirements\"\u003e\u003c/a\u003e\n   - SwiftUI\n   - iOS 13.0 or above\n\n## Installation\n\u003ca id=\"installation\"\u003e\u003c/a\u003e\nYou can access SwiftNet through [Swift Package Manager](https://github.com/apple/swift-package-manager).\n### Swift Package Manager (SPM)\n\u003ca id=\"spm\"\u003e\u003c/a\u003e\nIn xcode select:\n```\nFile \u003e Swift Packages \u003e Add Package Dependency...\n```\nThen paste this URL:\n```\nhttps://github.com/MMMagicCoder/SwiftNet.git\n```\n\n## Usage\n\u003ca id=\"usage\"\u003e\u003c/a\u003e\n`SwiftNet` provides a streamlined way to perform networking tasks. Whether you're fetching small data, downloading large files, or uploading content, you can choose between Escaping Closures, Combine, or async-await methods. To use these methods, instantiate the appropriate manager:\n- ```let networkManager = EscapingNetworkManager()``` for Escaping Closures.\n- ```let networkManager = CombineNetworkManager()``` for Combine.\n- ```let networkManager = AsyncNetworkManager()``` for async-await.\n  \nBelow are examples for each type of task.\n\n### Fetching Data\n\u003ca id=\"fetching\"\u003e\u003c/a\u003e\n\n`SwiftNet` provides two types of data fetching: `JSON Fetching` and `Data Fetching`. For JSON fetching, your model must conform to the `FetchableModel` protocol, which ensures the proper structure for decoding JSON responses.\n\n- JSON Fetching\n\nYou can fetch JSON data by using the following methods, depending on the approach you choose. Make sure your model conforms to FetchableModel:\n\n```swift\nstruct DataModel: FetchableModel {\n    let userId: Int\n    let id: Int\n    let title: String\n    let body: String\n}\n```\n\nUsing Escaping Closures\n\n```swift\n networkManager.fetchJSON(fromURL: \"https://example.com/api/data\") { (result: [MyModel]?, response, error) in\n    if let result = result {\n        // Handle the decoded JSON result\n    } else if let error = error {\n        // Handle the error\n    }\n}\n```\n\nUsing Combine\n\n```swift\n  networkManager.fetchJSON(fromURL: url) { (returnedData: [DataModel]?, response, error) in\n     if let result = result {\n         // Handle the decoded JSON result\n    } else if let error = error {\n        // Handle the error\n    }\n}\n```\n\nUsing async-await\n\n```swift\nTask {\n    do {\n        let result: [MyModel] = try await networkManager.fetchJSON(fromURL: \"https://example.com/api/data\")\n        // Handle the decoded JSON result\n    } catch {\n        // Handle the error\n    }\n}\n```\n\n- Data Fetching\n\n  Data fetching is used when you need to fetch raw data (e.g., images, binary files) without decoding it into a specific model.\n\n  Using Escaping Closures\n\n```swift\n  networkManager.fetchData(fromURL: \"https://example.com/file\") { data, response, error in\n    if let data = data {\n        // Handle the fetched data\n    } else if let error = error {\n        // Handle the error\n    }\n}\n```\n\nUsing Combine\n\n```swift\n networkManager.fetchData(fromURL: url) { (returnedData, response, error) in\n     if let result = result {\n         // Handle the returned data\n    } else if let error = error {\n        // Handle the error\n    }\n}\n```\n\nUsing async-await\n\n```swift\nTask {\n    do {\n        let data = try await networkManager.fetchData(fromURL: \"https://example.com/file\")\n        // Handle the fetched data\n    } catch {\n        // Handle the error\n    }\n}\n```\n\n### Downloading Files\n\u003ca id=\"downloading\"\u003e\u003c/a\u003e\n\nUsing Escaping Closures Or Combine\n\n```swift\nnetworkManager.downloadData(fromURL: url) { tempLocalUrl, response, error in\n    if let tempLocalUrl = tempLocalUrl {\n       // Get data from tempLocalUrl url\n  } else if error = error {\n       // Handle the error\n  }\n}\n```\n\nUsing async-await\n\n```swift\nTask {\n    do {\n        let fileURL = try await networkManager.downloadFile(using: .async)\n        // Use the file\n    } catch {\n        // Handle the error\n    }\n}\n```\n\n### Uploading Data\n\u003ca id=\"uploading\"\u003e\u003c/a\u003e\n\nUsing Escaping Closures Or Combine\n\n```swift\nnetworkManager.uploadData(toURL: url, data: json, mimeType: .json) { response , error in\n   if let error = error {\n       // Handle the error\n  } else {\n       // Handle the response \n  }\n}\n```\n\nUsing async-await\n\n```swift\n  Task {\n      do {\n          let returnedResponse = try await networkManager.uploadData(toURL: url, data: json, mimeType: .json)\n              // Handle the response\n   } catch {\n             // Handle the error\n  }\n}\n```\n\n### Contribution\n\u003ca id=\"contribution\"\u003e\u003c/a\u003e \nIf you encounter any issues, feel free to open an issue. Contributions are also welcome, whether it's bug fixes, new features, or documentation improvements.\n\n### License\n\n\u003ca id=\"license\"\u003e\u003c/a\u003e \nNetworkKit is distributed under the MIT License.\n```\nMIT License\n\nCopyright (c) 2024 Mohammad Mahdi Moayeri\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmmagiccoder%2Fswiftnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmmagiccoder%2Fswiftnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmmagiccoder%2Fswiftnet/lists"}