Objective-C ARC转换的几个问题

时间:2011-10-14 00:19:43

标签: objective-c automatic-ref-counting

我正在尝试将我的代码转换为Objective-C ARC并获得多个错误。

1:

NSBezierPath *path = [NSBezierPath bezierPath];
CGPathApply(pathRef,  path, CGPathCallback); //error

它说:ARC不允许将Objective.C指针隐式转换为'void *'

2:

static void CGPathCallback(void *info, const CGPathElement *element) {
NSBezierPath *path = info; //error
[…] }

它说:ARC不允许将非Objective-C指针类型'void *'隐式转换为'NSBezierPath *'

任何想法,我如何解决问题?

1 个答案:

答案 0 :(得分:7)

您需要使用bridged casts。在这种情况下,您只需要简单的__bridge修饰符,例如

NSBezierPath *path = [NSBezierPath bezierPath];
CGPathApply(pathRef, (__bridge void *)path, CGPathCallback);

static void CGPathCallback(void *info, const CGPathElement *element) {
    NSBezierPath *path = (__bridge NSBezierPath*)info;
    ...
}