0

How to implement Alamofire.NetworkReachabilityManager for global use in an application to check network connectivity in swift?

I want to use NetworkReachabilityManager to check internet connectivity but in global way.

IAmInPLS
  • 4,051
  • 4
  • 24
  • 57
Vibha Singh
  • 623
  • 4
  • 9
  • is the ques different from http://stackoverflow.com/questions/35427698/how-to-use-networkreachabilitymanager-in-alamofire ? – Shubhank Jun 06 '16 at 08:09
  • It is related with that but not same. I want to know that how can I use that singleton object globally. – Vibha Singh Jun 06 '16 at 08:11
  • maybe keep it in app delegate or make a DataManager class singleton separately for all your data request where you keep track of it. – Shubhank Jun 06 '16 at 08:13

1 Answers1

2

You can create a simple singleton like this:

import Alamofire

public class NetworkManager {
    public static var sharedManager: NetworkReachabilityManager = {
        let manager = NetworkReachabilityManager()
        // Add additional setup for the manager
        return manager!
    }()
}

And you can use it through the app like:

NetworkManager.sharedManager
Said Sikira
  • 4,482
  • 29
  • 42