{"id":16699996,"url":"https://github.com/dscyrescotti/reachabilityx","last_synced_at":"2025-04-10T03:47:58.244Z","repository":{"id":46780178,"uuid":"405569400","full_name":"dscyrescotti/ReachabilityX","owner":"dscyrescotti","description":"Make it easier to observe network connectivity in SwiftUI.","archived":false,"fork":false,"pushed_at":"2021-09-26T09:02:41.000Z","size":43,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-20T02:53:03.400Z","etag":null,"topics":["connectivity","networkconnection","reachability","swift","swiftpackagemanager","swiftui"],"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/dscyrescotti.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":"2021-09-12T06:53:04.000Z","updated_at":"2023-08-21T12:30:53.000Z","dependencies_parsed_at":"2022-09-17T18:53:35.707Z","dependency_job_id":null,"html_url":"https://github.com/dscyrescotti/ReachabilityX","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dscyrescotti%2FReachabilityX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dscyrescotti%2FReachabilityX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dscyrescotti%2FReachabilityX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dscyrescotti%2FReachabilityX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dscyrescotti","download_url":"https://codeload.github.com/dscyrescotti/ReachabilityX/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154994,"owners_count":21056542,"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":["connectivity","networkconnection","reachability","swift","swiftpackagemanager","swiftui"],"created_at":"2024-10-12T18:08:49.684Z","updated_at":"2025-04-10T03:47:58.223Z","avatar_url":"https://github.com/dscyrescotti.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ReachabilityX\n__ReachabilityX__ is built using `NWPathMonitor` from Apple's `Network` framework to provide an easy way to observe the network changes for SwiftUI.\n\n## Requirements\n-   iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+\n-   Swift 5.3+\n\n## Installation\n### Swift Package Manager\nAdd it as a dependency within your  `Package.swift`,\n```\ndependencies: [\n    .package(url: \"https://github.com/dscyrescotti/ReachabilityX\", from: \"1.0.0\")\n]\n```\nCurrently, **ReachabilityX** can only be installed via **Swift Package Manager**.\n\n## Usage\n__ReachabilityX__ comes with `ReachabilityView` that exposes `Reachability` object supplied from its parent or ancestor. It is pretty handy to use when network changes are needed to observe across multiple views.\n \n### Example 1\nFirstly, you need to create an instance of `Reachability` inside the entry point of an app for the purpose of sharing it across multiple views via `environmentObject(_:)`.\n```swift\n@main\nstruct TestApp: App {\n    @ObservedObject var reachability: Reachability = .init()\n    var body: some Scene {\n        WindowGroup {\n            ContentView()\n                .environmentObject(reachability)\n                .onAppear {\n                    reachability.start()\n                }\n        }\n    }\n}\n```\nNow, you can easily implement your presentation logic inside `ReachabilityView` and also implement your business logic using `onChangeStatus(action:)`,  `onChangeInterfaceType(action:)` and `onChangePath(action:)`.\n```swift\nstruct ContentView: View {\n    var body: some View {\n        ReachabilityView { (status: Status) in\n            // some presentation logic\n        }\n        .onChangeStatus { status in\n            // some business logic associated with status changes\n        }\n        .onChangeInterfaceType { interfaceType in\n            // some business logic associated with interface type changes\n        }\n        .onChangePath { path in\n            // some business logic associated with path changes\n        }\n    }\n}\n```\n`ReachabilityView` comes with a couple of initializers that allows you to construct your desired views inside closures with different parameters. \n```swift\n// use it when you are only interested in status\nReachabilityView { (status: Status) in\n    // some presentation logic associated with status changes\n}\n\n// use it when you are only interested in interface type\nReachabilityView { (interfaceType: InterfaceType) in\n    // some presentation logic associated with interface changes\n}\n\n// use it when you are interested in both of status and interface type\nReachabilityView { (status: Status, interfaceType: InterfaceType) in\n    // some presentation logic associated with status and interface type changes\n}\n\n// use it when you need to know the whole network path object\nReachabilityView { (path: NWPath) in\n    // some presentation logic associated with network path\n}\n```\n\n### Example 2\n__ReachabiliyX__ also allows you to create your own `Reachability` instance by declaring inside SwiftUI view to observe the network changes. \n```swift\nstruct ContentView: View {\n    @StateObject var reachability: Reachability = .init()\n    var body: some View {\n        Group {\n            switch reachability.status {\n            case .satisfied: Text(\"Connected!\")\n            default: Text(\"Not Connected!\")\n            }\n        }\n        .onAppear {\n            reachability.start()\n        }\n        .onDisappear {\n            reachability.stop()\n        }\n        .onChangeInterfaceType(reachability) { interfaceType in\n            // some business logic\n        }\n    }\n}\n```\n\n### Start and stop monitoring network changes\nTo obtain network path updates, you need to call `start()` method to begin observing network changes. If you want to stop observing changes, you have to call `stop()` method. This will no longer monitor any network changes.\n\n## Author\n**Dscyre Scotti** (**[@dscyrescotti](https://twitter.com/dscyrescotti)**)\n\n## Contributions\n\n**ReachabilityX**  welcomes all developers to contribute if you have any idea to improve and open an issue if you find any kind of bug.\n\n## License\n\nReachabilityX is available under the MIT license. See the  [LICENSE](https://github.com/dscyrescotti/ReachabilityX/blob/main/LICENSE)  file for more info.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdscyrescotti%2Freachabilityx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdscyrescotti%2Freachabilityx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdscyrescotti%2Freachabilityx/lists"}