title: How to convert CFArray to Swift Array?
body: <p>According to Apple's "Using Swift with Cocoa and Objective-C", "In Swift, you can use each pair of toll-free bridged Foundation and Core Foundation types interchangeably".  This makes working with Core Foundation sound way simpler than it actually is...</p>
  
  <p>I am trying to work with a CFArray that is returned from CoreText.  I have this code:</p>
  
  <pre><code>let lines: CFArrayRef  = CTFrameGetLines(frame)
  </code></pre>
  
  <p>I see two possible ways to access members of this array.  Neither is working for me right now.</p>
  
  <hr>
  
  <p>Way #1 - Use the CFArray directly</p>
  
  <pre><code>let line: CTLineRef = CFArrayGetValueAtIndex(lines, 0)
  </code></pre>
  
  <p>This yields the error "'ConstUnsafePointer&lt;()>' in not convertible to 'CTLineRef'".  Casting does not seem to change this error.</p>
  
  <p>Similarly, I would love to use lines "interchangeably" as a Swift array like it says that I can.  However,</p>
  
  <pre><code>let line: CTLineRef = lines[0]
  </code></pre>
  
  <p>yields the error "'CFArrayRef' does not have a member named 'subscript'"</p>
  
  <hr>
  
  <p>Way #2 - Convert the CFArray to a Swift array</p>
  
  <pre><code>var linesArray: Array = [CTLineRef]()
  linesArray = bridgeFromObjectiveC(lines, linesArray.dynamicType)
  </code></pre>
  
  <p>Here, I declared a Swift array and set it equal to the bridged CFArray.  This compiles without error, but when I run it, I get an EXC_BREAKPOINT crash on the second line.  Perhaps I'm not using the Swift language correctly on this one...</p>