title: Check for internet connection with Swift
body: <p>When I try to check for an internet connection on my iPhone I get a bunch of errors. Can anyone help me to fix this?</p>
  
  <p>The code:</p>
  
  <pre><code>import Foundation
  import SystemConfiguration
  
  public class Reachability {
  
  class func isConnectedToNetwork() -&gt; Bool {
  
      var zeroAddress = sockaddr_in()
      zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
      zeroAddress.sin_family = sa_family_t(AF_INET)
  
      let defaultRouteReachability = withUnsafePointer(&amp;zeroAddress) {
          SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))
      }
  
      var flags: SCNetworkReachabilityFlags = 0
  
      if SCNetworkReachabilityGetFlags(defaultRouteReachability, &amp;flags) == 0 {
          return false
      }
  
      let isReachable = (flags &amp; UInt32(kSCNetworkFlagsReachable)) != 0
      let needsConnection = (flags &amp; UInt32(kSCNetworkFlagsConnectionRequired)) != 0
  
      return (isReachable &amp;&amp; !needsConnection) ? true : false
  }
  
  }
  </code></pre>
  
  <p>The errors with the code:</p>
  
  <p><img src="https://i.stack.imgur.com/JaFMd.png" alt="Errors"></p>
  
  <p>If it is unreadable, error 1 says:</p>
  
  <blockquote>
    <p>'Int' is not convertible to 'SCNetworkReachabilityFlags'</p>
  </blockquote>
  
  <p>Error 2 &amp; 3:</p>
  
  <blockquote>
    <p>Could not find an overload for 'init' that accepts the supplied arguments</p>
  </blockquote>