用 Swift 编写的 CFTree

问题描述

我没有把以下内容转换成 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)