title: Using Simple Ping in swift (iOS)
body: <p>I'm trying to use Apple's class: Simple Ping, but I can't get this working.</p>
  
  <p>When I'm running example mac os x project it's working:</p>
  
  <blockquote>
    <p>2015-06-17 00:03:22.569 SimplePing[20386:3133535] pinging 192.168.1.102</p>
    
    <p>2015-06-17 00:03:22.569 SimplePing[20386:3133535] #0 sent </p>
    
    <p>2015-06-17 00:03:22.570 SimplePing[20386:3133535] #0 received</p>
    
    <p>2015-06-17 00:03:23.570 SimplePing[20386:3133535] #1 sent </p>
    
    <p>2015-06-17 00:03:23.571 SimplePing[20386:3133535] #1 received</p>
  </blockquote>
  
  <p>etc..</p>
  
  <p>But when I do it from my ios (swift) app:</p>
  
  <pre><code>let pinger = SimplePing(hostName: "192.168.1.102")
  pinger.delegate = self;
  pinger.start()
  
  do {
      NSRunLoop.currentRunLoop().runMode(NSDefaultRunLoopMode, beforeDate: NSDate.distantFuture() as! NSDate)
  } while(pinger != nil)
  </code></pre>
  
  <p>Not sure is do..while loop is needed - probably not needed. Anyway I tried without it too.</p>
  
  <p>And I've added SimplePingDelegate to my class:</p>
  
  <pre><code>    func simplePing(pinger: SimplePing!, didFailToSendPacket packet: NSData!, error: NSError!) {
          println("didFailToSendPacket")
      }
  
      func simplePing(pinger: SimplePing!, didFailWithError error: NSError!) {
          println("didFailWithError")
      }
  
      func simplePing(pinger: SimplePing!, didReceivePingResponsePacket packet: NSData!) {
          println("didReceivePingResponsePacket")
      }
  
      func simplePing(pinger: SimplePing!, didReceiveUnexpectedPacket packet: NSData!) {
          println("didReceiveUnexpectedPacket")
      }
  
      func simplePing(pinger: SimplePing!, didSendPacket packet: NSData!) {
          println("didSendPacket")
      }
  
      func simplePing(pinger: SimplePing!, didStartWithAddress address: NSData!) {
          println("didStartWithAddress")
      }
  </code></pre>
  
  <p>So it gives me output:</p>
  
  <blockquote>
    <p>2015-06-17 00:32:12.368 Available[938:150352] CFHostStartInfoResolution</p>
    
    <p>2015-06-17 00:32:12.374 Available[938:150352] >HostResolveCallback</p>
    
    <p>didStartWithAddress</p>
  </blockquote>
  
  <p>other functions aren't called. Why?</p>
  
  <p>Btw. I've also tried moving pinger into class variable like this:</p>
  
  <pre><code>var pinger: SimplePing?
  </code></pre>
  
  <p>No difference at all.</p>
  
  <p>How can I fix this?</p>