A lightweight, native, and zero-boilerplate network monitor for SwiftUI. Observe connectivity status and interface types (WiFi, Cellular, etc.) in real-time.
- Native Implementation: Built entirely using
NWPathMonitorfrom Apple's Network framework. - Zero Boilerplate: Access connectivity via the
Reachability.sharedsingleton. - SwiftUI Integration: First-class support for SwiftUI with
@StateObjectand view modifiers. - Detailed Status: Identify whether the user is on WiFi, Cellular, or Wired connection.
- Low Energy: Optimized for power efficiency by following best practices for network monitoring.
- iOS 14.0+
- macOS 11.0+
.package(url: "https://github.com/ErsanQ/ReachabilityKit", from: "1.0.0")import SwiftUI
import ReachabilityKit
struct MyView: View {
@StateObject private var network = Reachability.shared
var body: some View {
if network.isConnected {
Text("Connected via \(network.connectionType.rawValue)")
} else {
Text("Offline Mode")
}
}
}Text("App Content")
.onNetworkChange { isConnected in
if !isConnected {
print("Connectivity lost!")
}
}MIT License.
ErsanQ (Swift Package Index Community)
