swiftcore-foundation

CFTree written in Swift


I'm not getting far converting the following into 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);
}

I'm trying to set up the context with the following code

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

but it doesn't work.

How can I create and use a CFTree in Swift?


Solution

  • You can try something like this:

    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)