Question

I saw usage of this function in Mike Ash's post on ARC and wanted to play around with it but i just can't find where it resides. I haven't found it in objc/runtime and similar files, runtime documentation doesn't mention it, googling also gave nothing to me. What the secret function it is? Where is it? How do i import it?

Was it helpful?

Solution

objc_retainAutoreleaseReturnValue() and the related methods from the ARC runtime support are defined in /usr/lib/libobjc.A.dylib, but not exposed in the public header files.

When you download http://www.opensource.apple.com/source/objc4/objc4-551.1/ you will find the prototypes in "runtime/objc-internal.h", for example

// wraps objc_autorelease(objc_retain(obj)) in a useful way when used with return values
OBJC_EXPORT
id
objc_retainAutoreleaseReturnValue(id obj)
    __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0);

But I have no idea whether or not it is safe to call these internal runtime functions in your code. Some of them do very special things (like inspecting the callers code to check if an object has to be put into the autorelease pool or not).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top