How to import objc_retainAutoreleasedReturnValue?

折月煮酒 提交于 2019-12-13 06:05:50

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/20581627/how-to-import-objc-retainautoreleasedreturnvalue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!