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...
I am trying to work with a CFArray that is returned from CoreText. I have this code:
let lines: CFArrayRef = CTFrameGetLines(frame)
I see two possible ways to access members of this array. Neither is working for me right now.
Way #1 - Use the CFArray directly
let line: CTLineRef = CFArrayGetValueAtIndex(lines, 0)
This yields the error "'ConstUnsafePointer<()>' in not convertible to 'CTLineRef'". Casting does not seem to change this error.
Similarly, I would love to use lines "interchangeably" as a Swift array like it says that I can. However,
let line: CTLineRef = lines[0]
yields the error "'CFArrayRef' does not have a member named 'subscript'"
Way #2 - Convert the CFArray to a Swift array
var linesArray: Array = [CTLineRef]()
linesArray = bridgeFromObjectiveC(lines, linesArray.dynamicType)
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...