title: Using Apple's Reachability to check remote server reachability in Swift
body: <p>I'm developing an iOS application written in Swift that communicates with a HTTP server on the local network, and I'm using Apple's Reachability class to determine wether the remote machine running the HTTP server is online or not. Here's the code:</p>
  
  <pre><code>...
  let RemoteHost: String = "192.168.178.130"
  var RemoteReachability: Reachability! = nil
  var RemoteIsReachable: Bool = false
  
  init() {
          super.init()
          self.RemoteReachability = Reachability(hostName: self.RemoteHost)
          NSNotificationCenter.defaultCenter().addObserver(self, selector: "reachabilityChanged:", name: kReachabilityChangedNotification, object: self.RemoteReachability)
          self.RemoteReachability.startNotifier()
          self.RemoteIsReachable = (self.RemoteReachability.currentReachabilityStatus().value == ReachableViaWiFi.value)
  }
  
  func reachabilityChanged(notification: NSNotification) {
      let ReachabilityInst: Reachability = notification.object as Reachability
      self.RemoteIsReachable = (ReachabilityInst.currentReachabilityStatus().value == ReachableViaWiFi.value)
  }
  </code></pre>
  
  <p>The problem is that no matter if the remote machine is online or offline,</p>
  
  <pre><code>(ReachabilityInst.currentReachabilityStatus().value == ReachableViaWiFi.value)
  </code></pre>
  
  <p>Is always true, as long as I'm connected to a Wifi network. However, when I turn Wifi off, it results in being false instead of true. Am I doing something wrong here, or is the Reachability class just not compatible with Swift/xCode 6 Beta yet? I've also tried this:</p>
  
  <pre><code>(ReachabilityInst.currentReachabilityStatus() == ReachableViaWiFi)
  </code></pre>
  
  <p>But that results in xCode telling me "Could not find an overload for '==' that accepts the supplied arguments", even though both appear to be of type 'NetworkStatus'.</p>
  
  <p>Thanks in advance.</p>