title: How can I get a list of all windows, currently on the screen, in swift?
body: <p>How can I get a list of all windows, currently on the screen, in <strong><a href="https://developer.apple.com/swift/">swift</a></strong>? (all examples are preceded by <code>import Cocoa</code>)</p>
  
  <p>In <strong>objective-c</strong> I can run the following code successfully:</p>
  
  <pre><code>CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
  </code></pre>
  
  <p>But when I run the equivalent in <strong>swift</strong>(using the playground to test):</p>
  
  <pre><code>let windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kcGNullWindowID)
  </code></pre>
  
  <p>I get an error telling me that I have an <code>Use of unresolved identifier 'kcGNullWindowID'</code>. </p>
  
  <p>After playing around with the help of the <a href="https://developer.apple.com/library/mac/documentation/Carbon/reference/CGWindow_Reference/Constants/Constants.html">quartz documentation</a> for a while I have gotten to:</p>
  
  <pre><code>let windowList = CGWindowListCopyWindowInfo(CGWindowListOption(kCGWindowListOptionOnScreenOnly), CGWindowListOption(0))
  </code></pre>
  
  <p>But it still does not work as I am receiving a <code>{__NSArrayM}</code> object, which I do not know how to access.</p>
  
  <p>Am I on the right track or am I doing something fundamentally wrong?</p>