我正在尝试将我的代码转换为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 *'
任何想法,我如何解决问题?
答案 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;
...
}