title: Detect if internet connection is available (WIFI and 4G) on SWIFT 3
body: <p>Can anyone help me to find a way to detect if an Internet connection is available using Swift 3?</p>
  
  <p>I'm using the following code:</p>
  
  <pre><code>import Foundation
  import SystemConfiguration
  
  public class Reachability {
  
      class func isConnectedToNetwork() -&gt; Bool {
  
          var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))
          zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress))
          zeroAddress.sin_family = sa_family_t(AF_INET)
  
          let defaultRouteReachability = withUnsafePointer(to: &amp;zeroAddress) {
              SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, UnsafePointer)
          }
  
          var flags: SCNetworkReachabilityFlags = SCNetworkReachabilityFlags(rawValue: 0)
          if SCNetworkReachabilityGetFlags(defaultRouteReachability!, &amp;flags) == false {
              return false
          }
          let isReachable = flags == .reachable
          let needsConnection = flags == .connectionRequired
  
          return isReachable &amp;&amp; !needsConnection
      }
  }
  </code></pre>
  
  <p>but I have an error message:</p>
  
  <p><img src="https://i.stack.imgur.com/s6O6g.png" alt="Error Message"></p>