【问题标题】:ARC issue in function pointers using id in objective c在目标 c 中使用 id 的函数指针中的 ARC 问题
【发布时间】:2017-03-08 18:48:59
【问题描述】:

最近我是 ARC 机制的新手,我在下面提供的函数指针中发现了一个问题,该问题在非 ARC 中可以正常工作,但在 ARC 中不能正常工作

Please find the following piece of code

Class cls = objc_getAssociatedObject(object, originalClassVar);

ObjCPropertyInfo *propInfo = objc_getAssociatedObject(cls, selector);
struct objc_super objectSuper;
objectSuper.receiver = object;
objectSuper.super_class = cls;

id (*fPtrSuper)(struct objc_super*,SEL,float) = (id (*)(struct objc_super*,SEL,float))objc_msgSendSuper;
fPtrSuper(&objectSuper, selector, newVal);

如果我用 void 替换 Id 可以正常工作,请提供 cmets

【问题讨论】:

  • “不工作”是什么意思?但是,函数指针不受 ARC(或 MRR)的约束。
  • 那不是真正的代码。请显示真实代码。
  • HI Amin 和 matt 更新了代码,请检查。

标签: ios objective-c automatic-ref-counting


【解决方案1】:

尝试将id 替换为void

void (*fPtrSuper)(struct objc_super*,SEL,float) = (void (*)(struct objc_super*,SEL,float))objc_msgSendSuper;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 1970-01-01
    相关资源
    最近更新 更多