Skip to content

M-I-N/ReachabilityDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

ReachabilityDemo

Language

ReachabilityDemo is a demo iOS project that uses protocol oriented programming (POP) approach to monitor the changes in network reachability.

Usage

Any type that conforms to the Reachable protocol will be able to be notified when network connectivity changes.

Dependency

Reachability.swift file needs to be imported in the project.

Example

class FirstViewController: UIViewController, Reachable {
    // Reachable protocol requirement
    let reachability: Reachability = Reachability()!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Invoke the default implementation of the Reachable protocol requirement to be able to be notified
        startMonitoringReachabilityChangeStatus()
    }
    
    // Reachable protocol requirement
    func reachabilityChanged(to: Reachability.Connection) {
        // Everytime any change happens in the network connectivity this method will be invoked with appropriate connection status
        switch to {
        case .wifi:
            DispatchQueue.main.async {
                // Update any UI component
            }
        case .cellular:
            DispatchQueue.main.async {
                // Update any UI component
            }
        case .none:
            DispatchQueue.main.async {
                // Update any UI component
            }
        }
    }
}

Notices

The current version is working with Xcode Version Xcode 9.3 (9E145).

Releases

No releases published

Packages

No packages published

Languages