{"id":27366852,"url":"https://github.com/antonio-war/swiftyreachability","last_synced_at":"2025-04-13T06:40:20.500Z","repository":{"id":63903722,"uuid":"532809827","full_name":"antonio-war/SwiftyReachability","owner":"antonio-war","description":"SwiftyReachability is a simple and lightweight network interface manager written in Swift","archived":false,"fork":false,"pushed_at":"2022-11-04T22:47:19.000Z","size":55,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-03-14T17:13:07.426Z","etag":null,"topics":["cellular-network","delegate-pattern","ethernet","ios","network-observability","observer","observer-pattern","reachability","swift","swiftpackage","swiftpackagemanager","swiftui","swiftyreachability","wifi"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antonio-war.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-05T08:27:31.000Z","updated_at":"2023-03-29T08:43:31.000Z","dependencies_parsed_at":"2023-01-14T13:00:49.788Z","dependency_job_id":null,"html_url":"https://github.com/antonio-war/SwiftyReachability","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/antonio-war%2FSwiftyReachability","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonio-war%2FSwiftyReachability/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonio-war%2FSwiftyReachability/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonio-war%2FSwiftyReachability/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonio-war","download_url":"https://codeload.github.com/antonio-war/SwiftyReachability/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675434,"owners_count":21143763,"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":["cellular-network","delegate-pattern","ethernet","ios","network-observability","observer","observer-pattern","reachability","swift","swiftpackage","swiftpackagemanager","swiftui","swiftyreachability","wifi"],"created_at":"2025-04-13T06:40:19.549Z","updated_at":"2025-04-13T06:40:20.485Z","avatar_url":"https://github.com/antonio-war.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg width=\"1042\" alt=\"Schermata 2022-09-06 alle 10 04 08\" src=\"https://user-images.githubusercontent.com/59933379/188581267-2457d49c-119f-4109-9573-b1069c40ad37.png\"\u003e\n\u003c/p\u003e\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fantonio-war%2FSwiftyReachability%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/antonio-war/SwiftyReachability)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fantonio-war%2FSwiftyReachability%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/antonio-war/SwiftyReachability)\n\nSwiftyReachability is a simple and lightweight network interface manager written in Swift.\n\nFreely inspired by https://github.com/tonymillion/Reachability, with the aim of providing an updated interface that includes all the innovations introduced in the iOS world since its latest update and add new features.\n\n- **Easy to use:** no configuration needed, SwiftyReachability is ready to go.\n- **Shared:** it's based on a single istance shared by the whole app, you can access to the network layer's information at any time and any point.\n- **Detailed:** it allows you to know the connection type used and in the case of 'Cellular Network' you also know which radio technology is being used.\n- **SwiftUI compatible:** provides an elegant SwiftUI support that is very easy to use.\n- **Multiple Observers:** you can define several network Observers at the same time to get information and update your UI.\n\n---\n\n# Installation\n\nYou can use Swift Package Manager to add SwiftyReachability to your project.\n\n## Add Package Dependency\n\nIn Xcode, select File \u003e Add Packages...\n\n## Specify the Repository\n\nCopy and paste the following into the search/input box.\n\nhttps://github.com/antonio-war/SwiftyReachability\n\n## Specify options\n\nUse **Up to Next Major Version** as dependency rule and enter the current SwiftyReachability version.\nThen click **Add Package**.\n\n---\n\n# Overview\n\n## Connection Status\n\nSwiftyReachability's main purpose is to track device connectivity. Through **SwiftyConnectionStatus** it is possible to find out if it is online or offline.\n\n```swift\nenum SwiftyConnectionStatus {\n    case online\n    case offline\n}\n```\n\n## Connection Type\n\nWhen the device is online it may be useful to know information about the connection type. You can do it through **SwiftyConnectionType**.\n\n```swift\nenum SwiftyConnectionType {\n    case cellular(radioType: SwiftyRadioType)\n    case wifi\n    case ethernet\n}\n```\n## Radio Type\n\nUnlike original Reachability framework we introduced other information, when the device is connected to a cellular network you can know if it is using a 3G, LT or some other radio type, through **SwiftyRadioType**.\n\n```swift\nenum SwiftyRadioType {\n    case undefined\n    case _2G\n    case _3G\n    case _4G\n    case _5G\n}\n```\nOn some devices, however, this feature is not available, at least for now.\n\n---\n\n# Simple Usage\n\nIn case you need to access current information, without the need to be informed about future changes, it's possibile to do so by directly accessing to the shared instance of SwiftyReachability.\n\n```swift\nlet connectionManager = SwiftyReachability.shared\nlet status = connectionManager.connectionStatus\nlet type = connectionManager.connectionType      \n```\n---\n\n# Observer Usage\n\nWhen the status of your app needs to be updated based on the connection status you may need an observer. Obviously SwiftyReachability provides all the elements for this type of implementation.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://user-images.githubusercontent.com/59933379/188596659-347dd5e7-3a8b-45dc-9e06-19c3bc716280.gif\" width=\"200\" /\u003e\n\u003c/p\u003e\n\n## Swift / UIKit\n\nFor simple objects or view created with UIKit we provide a protocol oriented solution. The object must conform to the **SwiftyReachabilityObserver** protocol and implement the required methods.\nHe also has to decide when to start and stop the observation.\n\n```swift\nclass UIKitViewController: UIViewController, SwiftyReachabilityObserver {\n    \n    @IBOutlet weak var statusLabel: UILabel!\n    @IBOutlet weak var connectionTypeImage: UIImageView!\n    @IBOutlet weak var radioTypeLabel: UILabel!\n        \n    override func viewDidLoad() {\n        super.viewDidLoad()\n    }\n    \n    override func viewWillAppear(_ animated: Bool) {\n        super.viewWillAppear(animated)\n        startObserving()\n    }\n    \n    override func viewWillDisappear(_ animated: Bool) {\n        super.viewWillDisappear(animated)\n        stopObserving()\n    }\n    \n    func didChangeConnectionStatus(_ status: SwiftyConnectionStatus) {\n        DispatchQueue.main.async {\n            switch status {\n                case .online:\n                self.statusLabel.text = \"Online\"\n                self.statusLabel.backgroundColor = .systemGreen\n                case .offline:\n                self.statusLabel.text = \"Offline\"\n                self.statusLabel.backgroundColor = .systemRed\n            }\n        }\n    }\n    \n    func didChangeConnectionType(_ type: SwiftyConnectionType?) {\n        DispatchQueue.main.async {\n            guard let connectionType = type else {\n                self.connectionTypeImage.isHidden = true\n                self.radioTypeLabel.isHidden = true\n                return\n            }\n            \n            switch connectionType {\n            case .cellular(let radioType):\n                self.connectionTypeImage.image = UIImage(systemName: \"antenna.radiowaves.left.and.right\")\n                self.connectionTypeImage.isHidden = false\n                self.radioTypeLabel.text = radioType.description\n                self.radioTypeLabel.isHidden = false\n            case .wifi:\n                self.connectionTypeImage.image = UIImage(systemName: \"wifi\")\n                self.connectionTypeImage.isHidden = false\n                self.radioTypeLabel.isHidden = true\n            case .ethernet:\n                self.connectionTypeImage.image = UIImage(systemName: \"cable.connector\")\n                self.connectionTypeImage.isHidden = false\n                self.radioTypeLabel.isHidden = true\n            }\n        }\n    }\n}\n```\n\n## SwiftUI\n\nIn this case we have instead created an ad hoc solution with an ObservableObject. It is really easy to use **SwiftyReachabilityObserverUI**\n\n```swift\nstruct SwiftUIView: View {\n    \n    @ObservedObject\n    var connectionObserver : SwiftyReachabilityObserverUI = SwiftyReachabilityObserverUI()\n    \n    var body: some View {\n        VStack {\n            if connectionObserver.connectionStatus == .online {\n                Text(\"Online\")\n            } else {\n                Text(\"Offline\")\n            }\n            \n            if let connectionTypeDescription = connectionObserver.connectionType?.description {\n                Text(connectionTypeDescription)\n            }\n        }\n    }\n}\n```\n---\n# Advice\n\nLike any other package related to Reachability, in the case simulator execution, there may be delays in the functioning of the network observers. We therefore recommend testing your code on devices, where these problems do not occur.\n\n---\n# License\nSwiftyCache is published under the Apache 2.0 license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonio-war%2Fswiftyreachability","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonio-war%2Fswiftyreachability","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonio-war%2Fswiftyreachability/lists"}