Simple and extensible NetworkMonitor with UI Solution for Apple Platforms.
- iOS 17
- macOS 14
- visionOS 1.x
- File > Swift Packages > Add Package Dependency
- Copy and paste this URL
https://github.com/alfianlosari/XCANetworkMonitor
Import to your project source file.
import XCANetworkMonitor
Simply add networkStatusBanner()
modifier to your SwiftUI View.
var body: some View {
VStack(spacing: 20) {
Text("XCA Network Monitor Demo")
.font(.title)
}
.networkStatusBanner()
Simply initialize passing the NetworkMonitor
as @State
in SwiftUI View.
struct ContentView: View {
@State var networkMonitor = NetworkMonitor()
var body: some View {
HStack {
Circle()
.foregroundStyle(networkMonitor.isReachable ? .green : .red)
.frame(width: 20, height: 20)
Text(networkMonitor.statusText)
}
}
}