将object_setInstanceVariable()转换为ARC? [英] Converting object_setInstanceVariable() to ARC?

查看:267
本文介绍了将object_setInstanceVariable()转换为ARC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望转换

object_setInstanceVariable(self, [key UTF8String], *(id**)addr);

到ARC。当我尝试使用Xcode内置的Objective-C ARC转换器时,我收到以下错误:

to ARC. When I try to use Xcode built-in Objective-C ARC converter I get the following error:


'object_setInstanceVariable'不可用:不可用在自动引用计数模式下

'object_setInstanceVariable' is unavailable: not available in automatic reference counting mode

我该如何处理这个问题?我知道我可以将--fno-objc-arc作为编译器标志,但我非常想使用ARC,如果可能的话(我有很多目标,否则我必须手动更改编译器标志) 。

How should I handle this problem? I know I can put --fno-objc-arc as Compiler flag, but I would very much like to use ARC instead, if it's possible (I have a lot of targets that I otherwise would have to manually change the Compiler flag for).

(该代码最初来自 NSObject + NSCoding和Mike Mayo在Rackspace移动应用程序中的存档

推荐答案

来源: https://developer.apple.com/library/ios/#documentation/Cocoa/参考/ ObjCRuntimeRef /参考/ reference.html

唯一的其他方法是:

void object_setIvar(id object, Ivar ivar, id value);

您需要事先获得 Ivar 值,可以通过 class_getInstanceVariable(Class class,char * name)获得。

You need the Ivar value beforehand, which can be obtained via class_getInstanceVariable(Class class, char* name).

总体而言,这将达到与之前,虽然现在与ARC兼容。

Overall this will achieve the same effect as before, whilst now being ARC compatible.

这篇关于将object_setInstanceVariable()转换为ARC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆