3

I wish to convert an instance of

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

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

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

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).

(The code is originally taken from NSObject+NSCoding and Archiver by Mike Mayo at Rackspace Mobile Apps)

Anden87
  • 970
  • 1
  • 9
  • 19

1 Answers1

5

Source: https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html

The only other method to do this is:

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

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

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

WDUK
  • 18,870
  • 3
  • 64
  • 72
  • Thanks for your input! If there's no better solution the coming days I'm giving you the accept :) – Anden87 Nov 02 '12 at 15:37
  • @WDUK: `class_getInstanceVariable` seems to work and get you the `Ivar` even when ARC is enabled. – yairchu Oct 01 '13 at 13:36