Created
June 7, 2023 09:01
-
-
Save DavidBemerguy/dad42579abde390c47730b5a98f08122 to your computer and use it in GitHub Desktop.
Revisions
-
DavidBemerguy created this gist
Jun 7, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ import Network class PathMonitor: ObservableObject { @Published private(set) var status: NWPath.Status private let pathMonitor = NWPathMonitor() private let pathMonitorQueue = DispatchQueue(label: "NWPathMonitor") init(status: NWPath.Status = .unsatisfied, active: Bool = true) { self.status = status if active { enablePathMonitor() } } private func enablePathMonitor() { pathMonitor.pathUpdateHandler = { path in DispatchQueue.main.async { self.status = path.status } } pathMonitor.start(queue: pathMonitorQueue) } }