React To Network Status Changes With NWPathMonitor and SwiftUI
Daily Coding Tip 183
This is a quick example of how you can use NWPathMonitor to display information about the current device’s internet connection. Every time the network status changes, the path monitor runs a closure called the pathUpdateHandler. This closure is passed an NWPath value, which has information about the network connection.
All my update handler is doing is setting a State property to that NWPath, and my view is displaying that data.
Don’t forget that the path monitor needs to be started on a DispatchQueue, although the label can be anything.
Try installing this on your phone and turning on Airplane Mode!



