title: Using NSNetService and NSNetServiceBrowser on a Swift application
body: <p>I'd like to make an app that is able to discover and connect to peers on the local network, so i've decided to implement it in swift, using the bonjour framework.  </p>
  
  <p>However, i can't make Bonjour work using Swift, and I can't figure out why.  Here is the code I use to test this service : </p>
  
  <pre><code>import Foundation
  
  let BM_DOMAIN = "local"
  let BM_TYPE = "_helloworld._tcp."
  let BM_NAME = "hello"
  let BM_PORT : CInt = 6543
  
  /// Netservice
  let nsns = NSNetService(domain: BM_DOMAIN, 
          type: BM_TYPE, name: BM_NAME, port: BM_PORT)
  let nsnsdel = BMNSDelegate() //see bellow
  nsns.delegate = nsnsdel
  nsns.publish()
  
  /// Net service browser.
  let nsb = NSNetServiceBrowser()
  let nsbdel = BMBrowserDelegate() //see bellow
  nsb.delegate = nsbdel
  nsb.searchForServicesOfType(BM_TYPE, inDomain: BM_DOMAIN)
  
  println("press enter")
  // this prevents the app from quitting instantly.
  NSFileHandle.fileHandleWithStandardInput().availableData 
  </code></pre>
  
  <p>The delegates are glue code that simply prints every call to the console.</p>
  
  <pre><code>class BMNSDelegate : NSObject, NSNetServiceDelegate {
      func netServiceWillPublish(sender: NSNetService!) {
          println("netServiceWillPublish:sender");
      }
      // .....and so on for the 8 other methods.....
  }
  
  class BMBrowserDelegate : NSObject, NSNetServiceBrowserDelegate {
      func netServiceBrowserWillSearch(aNetServiceBrowser: NSNetServiceBrowser!){
          println("netServiceBrowserWillSearch")
      }
      // .....and so on for the 6 other methods.....
  }
  </code></pre>
  
  <p>Here is the output of this sample code : </p>
  
  <pre><code>netServiceWillPublish:sender
  netServiceBrowserWillSearch
  press enter
  </code></pre>
  
  <p>If I use <a href="http://www.tildesoft.com/" rel="nofollow">Bonjour browser</a>, I can see that the service is correctly published.  However the callbacks in both delegates are not called, beside the <code>**WillPublish</code> ones :-(</p>
  
  <p>After intense debugging (and reading on stackoverflow), I can't figure why it does not work. Any ideas ? </p>
  
  <p>(I'm using Mac OS X 10.9.3, and xcode 6.0 beta build 6A215l)</p>