title: Check Internet connection availability?
body: <p>I just need to check the internet connection availability before start communicating with the service in my iphone App. I am using Swift 1.2 and Xcode 6 as my development environment... </p>
  
  <p>I've just done some research and found this stackoverflow <a href="https://stackoverflow.com/questions/8812459/easiest-way-to-detect-internet-connection-on-ios">LINK</a>  in  objective C.</p>
  
  <p>Therefore I just tried to find a similar solution in SWIFT and found the following link</p>
  
  <p><a href="https://coderwall.com/p/mhxbpq/checking-for-internet-connection-availability" rel="nofollow noreferrer">https://coderwall.com/p/mhxbpq/checking-for-internet-connection-availability</a></p>
  
  <p>Just to make things easy the content in that link is as follows...</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(sizeofValue(zeroAddress))
        zeroAddress.sin_family = sa_family_t(AF_INET)
  
        let defaultRouteReachability = withUnsafePointer(&amp;zeroAddress) {
          SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)).takeRetainedValue()
        }
  
        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>And check the connection availability like this...</p>
  
  <pre><code>if Reachability.isConnectedToNetwork() 
  {
      println("Haz Interwebz!")
  }  
  else
  {
      println("Oh noes! No interwebz!!!")
  }
  </code></pre>
  
  <p><strong>NOTE:</strong> To work this needs to add <strong>SystemConfiguration.framework</strong> to the project (For "Linked Frameworks and Libraries")....</p>
  
  <p><strong>So....</strong> My question is, I am quite new for iOS development and NOT quite sure how good and relaible it is to use this logic to get it done. Most of the stuff in that class are completely not clear, but the small tests I've done works good!!!</p>
  
  <p>Like to hear what more experiance ios developers have to say about this.</p>