Ios Swift:在CFArray中提取/向下转换基于CFType的CoreText类型

Ios Swift:在CFArray中提取/向下转换基于CFType的CoreText类型,ios,macos,swift,core-text,core-foundation,Ios,Macos,Swift,Core Text,Core Foundation,我正在尝试将样本的元素移植到Swift。但是,我不知道如何从数组中提取或向下转换CTRun的元素,以便将它们传递给期望CTRun类型并对其执行操作的函数。我从下面的游乐场片段中获取运行时错误或链接错误 import CoreText import QuartzCore let text = NSAttributedString(string: "hello") var line: CTLine = CTLineCreateWithAttributedString(text) var ctRu

我正在尝试将样本的元素移植到Swift。但是,我不知道如何从数组中提取或向下转换CTRun的元素,以便将它们传递给期望CTRun类型并对其执行操作的函数。我从下面的游乐场片段中获取运行时错误或链接错误

import CoreText
import QuartzCore

let text = NSAttributedString(string: "hello")
var line: CTLine = CTLineCreateWithAttributedString(text)

var ctRuns:CFArray = CTLineGetGlyphRuns(line)

let nsRuns:Array<AnyObject> = ctRuns as NSArray
nsRuns.count // == 1
// Playground execution failed: error: error: Couldn't lookup symbols:_OBJC_CLASS_$_CTRun
let nsRun = nsRuns[0] as CTRun
nsRun.self
println(nsRun.self)

let anyRuns = nsRuns as AnyObject[]
// can't unwrap Optional null
let anyRun = anyRuns[0] as CTRun
anyRun.self
println(anyRun.self)


let cft:AnyObject = anyRuns[0]
// CTRun is not contstructable with AnyObject
let runGlyphCount = CTRunGetGlyphCount(CTRun(cft));


// Can't unwrap Optional.None
let concreteRuns = anyRuns as CTRun[]
let concreteRun = concreteRuns[0] as CTRun
concreteRun.self
println(concreteRun.self)
有什么想法吗?我是否遗漏了一些明显的东西?从WWDC会议和,我相信Swift会处理好这个问题。

根据,这个功能是在6.1中实现的

您的所有示例行编译时都没有错误,并在中按预期工作 最新的Xcode,6.1 6A1052c

与CF对象的互操作性正在提高。你可以再找一个 问题,在这种情况下,它将被报告为错误