错误:“使用未声明的标识符'CFTree'”

时间:2013-10-23 11:36:58

标签: ios objective-c core-foundation

我使用iOSCFTree应用程序中创建树。我收到错误“使用未声明的标识符'CFTree'”。我错过了什么? 我的代码:

#import "ViewController.h"
#import <CoreFoundation/CoreFoundation.h>

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    CFTree tree = CreateMyTree(kCFAllocatorDefault);
}

static CFTreeRef CreateMyTree(CFAllocatorRef allocator) {
    NSString *info = @"Bhushan is great";
    CFTreeContext ctx;
    ctx.version = 0;
    ctx.info = (__bridge void *)(info);
    ctx.retain = CFRetain;
    ctx.release = CFRelease;
    ctx.copyDescription = NULL;
    return CFTreeCreate(allocator, &ctx);
}

2 个答案:

答案 0 :(得分:0)

类型为CFTreeRef,而不是CFTree

CFTreeRef tree = CreateMyTree(kCFAllocatorDefault);

答案 1 :(得分:0)

试试这个:

NSString *info;
CFTreeContext ctx;

NSString *treeString = [[NSString alloc] initWithFormat:@"the tree string"];
info = treeString;

ctx.info = (__bridge void *)(info);
CFTreeRef myTree = CFTreeCreate(NULL, &ctx);

这是链接:Create a CFTree in Objective C