0

I'm facing a problem with reachability class in Swift, I'm using the following code to get it to work, but something seems to be wrong..

import Foundation

class NetworkConnect {

    static let sharedInstance = NetworkConnect()

    private init() {
    }

    func connected() -> Bool {
        var reachability : Reachability = Reachability.reachabilityForInternetConnection()
        var networkStatus : NetworkStatus = reachability.currentReachabilityStatus
        if networkStatus.value == NotReachable.value  {
            return false
        } else {
            return true
        }
    }
    }

I am getting this error:

'Reachability.NetworkStatus' is not convertible to 'NetworkStatus'

How can I fix that?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ashley Ivy
  • 193
  • 3
  • 14
  • Already present a similar question with an answer [http://stackoverflow.com/questions/25928826/using-apples-reachability-class-in-swift][1] [1]: http://stackoverflow.com/questions/25928826/using-apples-reachability-class-in-swift – Himanshu gupta Jun 06 '15 at 19:17

1 Answers1

0

Personally I would recommend you to use tonymillion's alternative to Reachability class, which can be found here:

https://github.com/tonymillion/Reachability

Then you can determine the connection in 1 line:

let connected: Bool = Reachability.reachabilityForInternetConnection().isReachable()

I would also recommend you to install this through CocoaPods if you have never tried that before. The reason being that Google will distribute all of their future iOS SDKs through CocoaPods, so you might start getting some practice with it already now :)

Kumuluzz
  • 2,012
  • 1
  • 13
  • 17