用 Swift 编写的 CFTree

CFTree written in Swift

我不会将以下内容转换为 Swift:

static CFTreeRef CreateMyTree(CFTypeRef rootObject) {
CFTreeContext ctx;
ctx.version = 0;
ctx.info = rootObject;
ctx.retain = CFRetain;
ctx.release = CFRelease;
ctx.copyDescription = CFCopyDescription;  
return CFTreeCreate(NULL, &ctx);
}

我正在尝试使用以下代码设置上下文

let context = CFTreeContext(version: 1, info: nil, retain: CFRetain, release: CFRelease, copyDescription: CFCopyDescription)

但是没用。

如何在 Swift 中创建和使用 CFTree?

您可以尝试这样的操作:

var info = "info"
let ctx = CFTreeContext(version: 0, info: &info, retain: nil, release: nil, copyDescription: nil)
let tree = CFTreeCreate(nil, [ctx])
let child1 = CFTreeCreate(nil, [ctx])
print(tree)