```swift
let hubEventListener = Amplify.Hub.listen(to: .dataStore) { event in
if event.eventName == HubPayload.EventName.DataStore.networkStatus {
guard let networkStatus = event.data as? NetworkStatusEvent else {
print("Failed to cast data as NetworkStatusEvent")
return
}
print("User receives a network connection status: \(networkStatus.active)")
}
}
```
```swift
let hubEventSubscriber = Amplify.Hub.publisher(for: .dataStore).sink { event in
if event.eventName == HubPayload.EventName.DataStore.networkStatus {
guard let networkStatus = event.data as? NetworkStatusEvent else {
print("Failed to cast data as NetworkStatusEvent")
return
}
print("User receives a network connection status: \(networkStatus.active)")
}
}
```
An initial `networkStatus` event is always dispatched, in which `active` is set to `false`. Shortly thereafter, you will receive an updated event that reflects the true status of the network connectivity.
You may want to setup your Hub Listener or Subscriber before calling `Amplify.configure()`, otherwise you may miss some of the `DataStore` events that are emitted.