【问题标题】:CFTree written in Swift用 Swift 编写的 CFTree
【发布时间】:2021-03-29 16:28:57
【问题描述】:

我不会将以下内容转换为 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?

【问题讨论】:

    标签: swift core-foundation


    【解决方案1】:

    你可以试试这样的:

    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)
    

    【讨论】:

    • 在 CFTree 中禁用保留/释放是否正常工作?如果对象没有被 ARC 保留在其他地方,我会非常担心它会变成一个悬空指针,因为 CFTree 不会保留它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-27
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 1970-01-01
    相关资源
    最近更新 更多