runtime.h 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177
  1. /*
  2. * Copyright (c) 1999-2007 Apple Inc. All Rights Reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  6. * This file contains Original Code and/or Modifications of Original Code
  7. * as defined in and that are subject to the Apple Public Source License
  8. * Version 2.0 (the 'License'). You may not use this file except in
  9. * compliance with the License. Please obtain a copy of the License at
  10. * http://www.opensource.apple.com/apsl/ and read it before using this
  11. * file.
  12. *
  13. * The Original Code and all software distributed under the License are
  14. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  15. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  16. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  18. * Please see the License for the specific language governing rights and
  19. * limitations under the License.
  20. *
  21. * @APPLE_LICENSE_HEADER_END@
  22. */
  23. #ifndef _OBJC_RUNTIME_H
  24. #define _OBJC_RUNTIME_H
  25. #include <objc/objc.h>
  26. #include <stdarg.h>
  27. #include <stdint.h>
  28. #include <stddef.h>
  29. #include <Availability.h>
  30. #include <TargetConditionals.h>
  31. #if TARGET_OS_MAC
  32. #include <sys/types.h>
  33. #endif
  34. /* Types */
  35. #if !OBJC_TYPES_DEFINED
  36. /// An opaque type that represents a method in a class definition.
  37. typedef struct objc_method *Method;
  38. /// An opaque type that represents an instance variable.
  39. typedef struct objc_ivar *Ivar;
  40. /// An opaque type that represents a category.
  41. typedef struct objc_category *Category;
  42. /// An opaque type that represents an Objective-C declared property.
  43. typedef struct objc_property *objc_property_t;
  44. struct objc_class {
  45. Class _Nonnull isa OBJC_ISA_AVAILABILITY;
  46. #if !__OBJC2__
  47. Class _Nullable super_class OBJC2_UNAVAILABLE;
  48. const char * _Nonnull name OBJC2_UNAVAILABLE;
  49. long version OBJC2_UNAVAILABLE;
  50. long info OBJC2_UNAVAILABLE;
  51. long instance_size OBJC2_UNAVAILABLE;
  52. struct objc_ivar_list * _Nullable ivars OBJC2_UNAVAILABLE;
  53. struct objc_method_list * _Nullable * _Nullable methodLists OBJC2_UNAVAILABLE;
  54. struct objc_cache * _Nonnull cache OBJC2_UNAVAILABLE;
  55. struct objc_protocol_list * _Nullable protocols OBJC2_UNAVAILABLE;
  56. #endif
  57. } OBJC2_UNAVAILABLE;
  58. /* Use `Class` instead of `struct objc_class *` */
  59. #endif
  60. #ifdef __OBJC__
  61. @class Protocol;
  62. #else
  63. typedef struct objc_object Protocol;
  64. #endif
  65. /// Defines a method
  66. struct objc_method_description {
  67. SEL _Nullable name; /**< The name of the method */
  68. char * _Nullable types; /**< The types of the method arguments */
  69. };
  70. /// Defines a property attribute
  71. typedef struct {
  72. const char * _Nonnull name; /**< The name of the attribute */
  73. const char * _Nonnull value; /**< The value of the attribute (usually empty) */
  74. } objc_property_attribute_t;
  75. /* Functions */
  76. /* Working with Instances */
  77. /**
  78. * Returns a copy of a given object.
  79. *
  80. * @param obj An Objective-C object.
  81. * @param size The size of the object \e obj.
  82. *
  83. * @return A copy of \e obj.
  84. */
  85. OBJC_EXPORT id _Nullable object_copy(id _Nullable obj, size_t size)
  86. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0)
  87. OBJC_ARC_UNAVAILABLE;
  88. /**
  89. * Frees the memory occupied by a given object.
  90. *
  91. * @param obj An Objective-C object.
  92. *
  93. * @return nil
  94. */
  95. OBJC_EXPORT id _Nullable
  96. object_dispose(id _Nullable obj)
  97. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0)
  98. OBJC_ARC_UNAVAILABLE;
  99. /**
  100. * Returns the class of an object.
  101. *
  102. * @param obj The object you want to inspect.
  103. *
  104. * @return The class object of which \e object is an instance,
  105. * or \c Nil if \e object is \c nil.
  106. */
  107. OBJC_EXPORT Class _Nullable
  108. object_getClass(id _Nullable obj)
  109. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  110. /**
  111. * Sets the class of an object.
  112. *
  113. * @param obj The object to modify.
  114. * @param cls A class object.
  115. *
  116. * @return The previous value of \e object's class, or \c Nil if \e object is \c nil.
  117. */
  118. OBJC_EXPORT Class _Nullable
  119. object_setClass(id _Nullable obj, Class _Nonnull cls)
  120. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  121. /**
  122. * Returns whether an object is a class object.
  123. *
  124. * @param obj An Objective-C object.
  125. *
  126. * @return true if the object is a class or metaclass, false otherwise.
  127. */
  128. OBJC_EXPORT BOOL
  129. object_isClass(id _Nullable obj)
  130. OBJC_AVAILABLE(10.10, 8.0, 9.0, 1.0, 2.0);
  131. /**
  132. * Reads the value of an instance variable in an object.
  133. *
  134. * @param obj The object containing the instance variable whose value you want to read.
  135. * @param ivar The Ivar describing the instance variable whose value you want to read.
  136. *
  137. * @return The value of the instance variable specified by \e ivar, or \c nil if \e object is \c nil.
  138. *
  139. * @note \c object_getIvar is faster than \c object_getInstanceVariable if the Ivar
  140. * for the instance variable is already known.
  141. */
  142. OBJC_EXPORT id _Nullable
  143. object_getIvar(id _Nullable obj, Ivar _Nonnull ivar)
  144. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  145. /**
  146. * Sets the value of an instance variable in an object.
  147. *
  148. * @param obj The object containing the instance variable whose value you want to set.
  149. * @param ivar The Ivar describing the instance variable whose value you want to set.
  150. * @param value The new value for the instance variable.
  151. *
  152. * @note Instance variables with known memory management (such as ARC strong and weak)
  153. * use that memory management. Instance variables with unknown memory management
  154. * are assigned as if they were unsafe_unretained.
  155. * @note \c object_setIvar is faster than \c object_setInstanceVariable if the Ivar
  156. * for the instance variable is already known.
  157. */
  158. OBJC_EXPORT void
  159. object_setIvar(id _Nullable obj, Ivar _Nonnull ivar, id _Nullable value)
  160. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  161. /**
  162. * Sets the value of an instance variable in an object.
  163. *
  164. * @param obj The object containing the instance variable whose value you want to set.
  165. * @param ivar The Ivar describing the instance variable whose value you want to set.
  166. * @param value The new value for the instance variable.
  167. *
  168. * @note Instance variables with known memory management (such as ARC strong and weak)
  169. * use that memory management. Instance variables with unknown memory management
  170. * are assigned as if they were strong.
  171. * @note \c object_setIvar is faster than \c object_setInstanceVariable if the Ivar
  172. * for the instance variable is already known.
  173. */
  174. OBJC_EXPORT void
  175. object_setIvarWithStrongDefault(id _Nullable obj, Ivar _Nonnull ivar,
  176. id _Nullable value)
  177. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  178. /**
  179. * Changes the value of an instance variable of a class instance.
  180. *
  181. * @param obj A pointer to an instance of a class. Pass the object containing
  182. * the instance variable whose value you wish to modify.
  183. * @param name A C string. Pass the name of the instance variable whose value you wish to modify.
  184. * @param value The new value for the instance variable.
  185. *
  186. * @return A pointer to the \c Ivar data structure that defines the type and
  187. * name of the instance variable specified by \e name.
  188. *
  189. * @note Instance variables with known memory management (such as ARC strong and weak)
  190. * use that memory management. Instance variables with unknown memory management
  191. * are assigned as if they were unsafe_unretained.
  192. */
  193. OBJC_EXPORT Ivar _Nullable
  194. object_setInstanceVariable(id _Nullable obj, const char * _Nonnull name,
  195. void * _Nullable value)
  196. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0)
  197. OBJC_ARC_UNAVAILABLE;
  198. /**
  199. * Changes the value of an instance variable of a class instance.
  200. *
  201. * @param obj A pointer to an instance of a class. Pass the object containing
  202. * the instance variable whose value you wish to modify.
  203. * @param name A C string. Pass the name of the instance variable whose value you wish to modify.
  204. * @param value The new value for the instance variable.
  205. *
  206. * @return A pointer to the \c Ivar data structure that defines the type and
  207. * name of the instance variable specified by \e name.
  208. *
  209. * @note Instance variables with known memory management (such as ARC strong and weak)
  210. * use that memory management. Instance variables with unknown memory management
  211. * are assigned as if they were strong.
  212. */
  213. OBJC_EXPORT Ivar _Nullable
  214. object_setInstanceVariableWithStrongDefault(id _Nullable obj,
  215. const char * _Nonnull name,
  216. void * _Nullable value)
  217. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0)
  218. OBJC_ARC_UNAVAILABLE;
  219. /**
  220. * Obtains the value of an instance variable of a class instance.
  221. *
  222. * @param obj A pointer to an instance of a class. Pass the object containing
  223. * the instance variable whose value you wish to obtain.
  224. * @param name A C string. Pass the name of the instance variable whose value you wish to obtain.
  225. * @param outValue On return, contains a pointer to the value of the instance variable.
  226. *
  227. * @return A pointer to the \c Ivar data structure that defines the type and name of
  228. * the instance variable specified by \e name.
  229. */
  230. OBJC_EXPORT Ivar _Nullable
  231. object_getInstanceVariable(id _Nullable obj, const char * _Nonnull name,
  232. void * _Nullable * _Nullable outValue)
  233. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0)
  234. OBJC_ARC_UNAVAILABLE;
  235. /* Obtaining Class Definitions */
  236. /**
  237. * Returns the class definition of a specified class.
  238. *
  239. * @param name The name of the class to look up.
  240. *
  241. * @return The Class object for the named class, or \c nil
  242. * if the class is not registered with the Objective-C runtime.
  243. *
  244. * @note \c objc_getClass is different from \c objc_lookUpClass in that if the class
  245. * is not registered, \c objc_getClass calls the class handler callback and then checks
  246. * a second time to see whether the class is registered. \c objc_lookUpClass does
  247. * not call the class handler callback.
  248. *
  249. * @warning Earlier implementations of this function (prior to OS X v10.0)
  250. * terminate the program if the class does not exist.
  251. */
  252. OBJC_EXPORT Class _Nullable
  253. objc_getClass(const char * _Nonnull name)
  254. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  255. /**
  256. * Returns the metaclass definition of a specified class.
  257. *
  258. * @param name The name of the class to look up.
  259. *
  260. * @return The \c Class object for the metaclass of the named class, or \c nil if the class
  261. * is not registered with the Objective-C runtime.
  262. *
  263. * @note If the definition for the named class is not registered, this function calls the class handler
  264. * callback and then checks a second time to see if the class is registered. However, every class
  265. * definition must have a valid metaclass definition, and so the metaclass definition is always returned,
  266. * whether it’s valid or not.
  267. */
  268. OBJC_EXPORT Class _Nullable
  269. objc_getMetaClass(const char * _Nonnull name)
  270. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  271. /**
  272. * Returns the class definition of a specified class.
  273. *
  274. * @param name The name of the class to look up.
  275. *
  276. * @return The Class object for the named class, or \c nil if the class
  277. * is not registered with the Objective-C runtime.
  278. *
  279. * @note \c objc_getClass is different from this function in that if the class is not
  280. * registered, \c objc_getClass calls the class handler callback and then checks a second
  281. * time to see whether the class is registered. This function does not call the class handler callback.
  282. */
  283. OBJC_EXPORT Class _Nullable
  284. objc_lookUpClass(const char * _Nonnull name)
  285. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  286. /**
  287. * Returns the class definition of a specified class.
  288. *
  289. * @param name The name of the class to look up.
  290. *
  291. * @return The Class object for the named class.
  292. *
  293. * @note This function is the same as \c objc_getClass, but kills the process if the class is not found.
  294. * @note This function is used by ZeroLink, where failing to find a class would be a compile-time link error without ZeroLink.
  295. */
  296. OBJC_EXPORT Class _Nonnull
  297. objc_getRequiredClass(const char * _Nonnull name)
  298. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  299. /**
  300. * Obtains the list of registered class definitions.
  301. *
  302. * @param buffer An array of \c Class values. On output, each \c Class value points to
  303. * one class definition, up to either \e bufferCount or the total number of registered classes,
  304. * whichever is less. You can pass \c NULL to obtain the total number of registered class
  305. * definitions without actually retrieving any class definitions.
  306. * @param bufferCount An integer value. Pass the number of pointers for which you have allocated space
  307. * in \e buffer. On return, this function fills in only this number of elements. If this number is less
  308. * than the number of registered classes, this function returns an arbitrary subset of the registered classes.
  309. *
  310. * @return An integer value indicating the total number of registered classes.
  311. *
  312. * @note The Objective-C runtime library automatically registers all the classes defined in your source code.
  313. * You can create class definitions at runtime and register them with the \c objc_addClass function.
  314. *
  315. * @warning You cannot assume that class objects you get from this function are classes that inherit from \c NSObject,
  316. * so you cannot safely call any methods on such classes without detecting that the method is implemented first.
  317. */
  318. OBJC_EXPORT int
  319. objc_getClassList(Class _Nonnull * _Nullable buffer, int bufferCount)
  320. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  321. /**
  322. * Creates and returns a list of pointers to all registered class definitions.
  323. *
  324. * @param outCount An integer pointer used to store the number of classes returned by
  325. * this function in the list. It can be \c nil.
  326. *
  327. * @return A nil terminated array of classes. It must be freed with \c free().
  328. *
  329. * @see objc_getClassList
  330. */
  331. OBJC_EXPORT Class _Nonnull * _Nullable
  332. objc_copyClassList(unsigned int * _Nullable outCount)
  333. OBJC_AVAILABLE(10.7, 3.1, 9.0, 1.0, 2.0);
  334. /* Working with Classes */
  335. /**
  336. * Returns the name of a class.
  337. *
  338. * @param cls A class object.
  339. *
  340. * @return The name of the class, or the empty string if \e cls is \c Nil.
  341. */
  342. OBJC_EXPORT const char * _Nonnull
  343. class_getName(Class _Nullable cls)
  344. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  345. /**
  346. * Returns a Boolean value that indicates whether a class object is a metaclass.
  347. *
  348. * @param cls A class object.
  349. *
  350. * @return \c YES if \e cls is a metaclass, \c NO if \e cls is a non-meta class,
  351. * \c NO if \e cls is \c Nil.
  352. */
  353. OBJC_EXPORT BOOL
  354. class_isMetaClass(Class _Nullable cls)
  355. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  356. /**
  357. * Returns the superclass of a class.
  358. *
  359. * @param cls A class object.
  360. *
  361. * @return The superclass of the class, or \c Nil if
  362. * \e cls is a root class, or \c Nil if \e cls is \c Nil.
  363. *
  364. * @note You should usually use \c NSObject's \c superclass method instead of this function.
  365. */
  366. OBJC_EXPORT Class _Nullable
  367. class_getSuperclass(Class _Nullable cls)
  368. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  369. /**
  370. * Sets the superclass of a given class.
  371. *
  372. * @param cls The class whose superclass you want to set.
  373. * @param newSuper The new superclass for cls.
  374. *
  375. * @return The old superclass for cls.
  376. *
  377. * @warning You should not use this function.
  378. */
  379. OBJC_EXPORT Class _Nonnull
  380. class_setSuperclass(Class _Nonnull cls, Class _Nonnull newSuper)
  381. __OSX_DEPRECATED(10.5, 10.5, "not recommended")
  382. __IOS_DEPRECATED(2.0, 2.0, "not recommended")
  383. __TVOS_DEPRECATED(9.0, 9.0, "not recommended")
  384. __WATCHOS_DEPRECATED(1.0, 1.0, "not recommended")
  385. #ifndef __APPLE_BLEACH_SDK__
  386. __BRIDGEOS_DEPRECATED(2.0, 2.0, "not recommended")
  387. #endif
  388. ;
  389. /**
  390. * Returns the version number of a class definition.
  391. *
  392. * @param cls A pointer to a \c Class data structure. Pass
  393. * the class definition for which you wish to obtain the version.
  394. *
  395. * @return An integer indicating the version number of the class definition.
  396. *
  397. * @see class_setVersion
  398. */
  399. OBJC_EXPORT int
  400. class_getVersion(Class _Nullable cls)
  401. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  402. /**
  403. * Sets the version number of a class definition.
  404. *
  405. * @param cls A pointer to an Class data structure.
  406. * Pass the class definition for which you wish to set the version.
  407. * @param version An integer. Pass the new version number of the class definition.
  408. *
  409. * @note You can use the version number of the class definition to provide versioning of the
  410. * interface that your class represents to other classes. This is especially useful for object
  411. * serialization (that is, archiving of the object in a flattened form), where it is important to
  412. * recognize changes to the layout of the instance variables in different class-definition versions.
  413. * @note Classes derived from the Foundation framework \c NSObject class can set the class-definition
  414. * version number using the \c setVersion: class method, which is implemented using the \c class_setVersion function.
  415. */
  416. OBJC_EXPORT void
  417. class_setVersion(Class _Nullable cls, int version)
  418. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  419. /**
  420. * Returns the size of instances of a class.
  421. *
  422. * @param cls A class object.
  423. *
  424. * @return The size in bytes of instances of the class \e cls, or \c 0 if \e cls is \c Nil.
  425. */
  426. OBJC_EXPORT size_t
  427. class_getInstanceSize(Class _Nullable cls)
  428. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  429. /**
  430. * Returns the \c Ivar for a specified instance variable of a given class.
  431. *
  432. * @param cls The class whose instance variable you wish to obtain.
  433. * @param name The name of the instance variable definition to obtain.
  434. *
  435. * @return A pointer to an \c Ivar data structure containing information about
  436. * the instance variable specified by \e name.
  437. */
  438. OBJC_EXPORT Ivar _Nullable
  439. class_getInstanceVariable(Class _Nullable cls, const char * _Nonnull name)
  440. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  441. /**
  442. * Returns the Ivar for a specified class variable of a given class.
  443. *
  444. * @param cls The class definition whose class variable you wish to obtain.
  445. * @param name The name of the class variable definition to obtain.
  446. *
  447. * @return A pointer to an \c Ivar data structure containing information about the class variable specified by \e name.
  448. */
  449. OBJC_EXPORT Ivar _Nullable
  450. class_getClassVariable(Class _Nullable cls, const char * _Nonnull name)
  451. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  452. /**
  453. * Describes the instance variables declared by a class.
  454. *
  455. * @param cls The class to inspect.
  456. * @param outCount On return, contains the length of the returned array.
  457. * If outCount is NULL, the length is not returned.
  458. *
  459. * @return An array of pointers of type Ivar describing the instance variables declared by the class.
  460. * Any instance variables declared by superclasses are not included. The array contains *outCount
  461. * pointers followed by a NULL terminator. You must free the array with free().
  462. *
  463. * If the class declares no instance variables, or cls is Nil, NULL is returned and *outCount is 0.
  464. */
  465. OBJC_EXPORT Ivar _Nonnull * _Nullable
  466. class_copyIvarList(Class _Nullable cls, unsigned int * _Nullable outCount)
  467. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  468. /**
  469. * Returns a specified instance method for a given class.
  470. *
  471. * @param cls The class you want to inspect.
  472. * @param name The selector of the method you want to retrieve.
  473. *
  474. * @return The method that corresponds to the implementation of the selector specified by
  475. * \e name for the class specified by \e cls, or \c NULL if the specified class or its
  476. * superclasses do not contain an instance method with the specified selector.
  477. *
  478. * @note This function searches superclasses for implementations, whereas \c class_copyMethodList does not.
  479. */
  480. OBJC_EXPORT Method _Nullable
  481. class_getInstanceMethod(Class _Nullable cls, SEL _Nonnull name)
  482. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  483. /**
  484. * Returns a pointer to the data structure describing a given class method for a given class.
  485. *
  486. * @param cls A pointer to a class definition. Pass the class that contains the method you want to retrieve.
  487. * @param name A pointer of type \c SEL. Pass the selector of the method you want to retrieve.
  488. *
  489. * @return A pointer to the \c Method data structure that corresponds to the implementation of the
  490. * selector specified by aSelector for the class specified by aClass, or NULL if the specified
  491. * class or its superclasses do not contain an instance method with the specified selector.
  492. *
  493. * @note Note that this function searches superclasses for implementations,
  494. * whereas \c class_copyMethodList does not.
  495. */
  496. OBJC_EXPORT Method _Nullable
  497. class_getClassMethod(Class _Nullable cls, SEL _Nonnull name)
  498. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  499. /**
  500. * Returns the function pointer that would be called if a
  501. * particular message were sent to an instance of a class.
  502. *
  503. * @param cls The class you want to inspect.
  504. * @param name A selector.
  505. *
  506. * @return The function pointer that would be called if \c [object name] were called
  507. * with an instance of the class, or \c NULL if \e cls is \c Nil.
  508. *
  509. * @note \c class_getMethodImplementation may be faster than \c method_getImplementation(class_getInstanceMethod(cls, name)).
  510. * @note The function pointer returned may be a function internal to the runtime instead of
  511. * an actual method implementation. For example, if instances of the class do not respond to
  512. * the selector, the function pointer returned will be part of the runtime's message forwarding machinery.
  513. */
  514. OBJC_EXPORT IMP _Nullable
  515. class_getMethodImplementation(Class _Nullable cls, SEL _Nonnull name)
  516. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  517. /**
  518. * Returns the function pointer that would be called if a particular
  519. * message were sent to an instance of a class.
  520. *
  521. * @param cls The class you want to inspect.
  522. * @param name A selector.
  523. *
  524. * @return The function pointer that would be called if \c [object name] were called
  525. * with an instance of the class, or \c NULL if \e cls is \c Nil.
  526. */
  527. OBJC_EXPORT IMP _Nullable
  528. class_getMethodImplementation_stret(Class _Nullable cls, SEL _Nonnull name)
  529. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0)
  530. OBJC_ARM64_UNAVAILABLE;
  531. /**
  532. * Returns a Boolean value that indicates whether instances of a class respond to a particular selector.
  533. *
  534. * @param cls The class you want to inspect.
  535. * @param sel A selector.
  536. *
  537. * @return \c YES if instances of the class respond to the selector, otherwise \c NO.
  538. *
  539. * @note You should usually use \c NSObject's \c respondsToSelector: or \c instancesRespondToSelector:
  540. * methods instead of this function.
  541. */
  542. OBJC_EXPORT BOOL
  543. class_respondsToSelector(Class _Nullable cls, SEL _Nonnull sel)
  544. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  545. /**
  546. * Describes the instance methods implemented by a class.
  547. *
  548. * @param cls The class you want to inspect.
  549. * @param outCount On return, contains the length of the returned array.
  550. * If outCount is NULL, the length is not returned.
  551. *
  552. * @return An array of pointers of type Method describing the instance methods
  553. * implemented by the class—any instance methods implemented by superclasses are not included.
  554. * The array contains *outCount pointers followed by a NULL terminator. You must free the array with free().
  555. *
  556. * If cls implements no instance methods, or cls is Nil, returns NULL and *outCount is 0.
  557. *
  558. * @note To get the class methods of a class, use \c class_copyMethodList(object_getClass(cls), &count).
  559. * @note To get the implementations of methods that may be implemented by superclasses,
  560. * use \c class_getInstanceMethod or \c class_getClassMethod.
  561. */
  562. OBJC_EXPORT Method _Nonnull * _Nullable
  563. class_copyMethodList(Class _Nullable cls, unsigned int * _Nullable outCount)
  564. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  565. /**
  566. * Returns a Boolean value that indicates whether a class conforms to a given protocol.
  567. *
  568. * @param cls The class you want to inspect.
  569. * @param protocol A protocol.
  570. *
  571. * @return YES if cls conforms to protocol, otherwise NO.
  572. *
  573. * @note You should usually use NSObject's conformsToProtocol: method instead of this function.
  574. */
  575. OBJC_EXPORT BOOL
  576. class_conformsToProtocol(Class _Nullable cls, Protocol * _Nullable protocol)
  577. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  578. /**
  579. * Describes the protocols adopted by a class.
  580. *
  581. * @param cls The class you want to inspect.
  582. * @param outCount On return, contains the length of the returned array.
  583. * If outCount is NULL, the length is not returned.
  584. *
  585. * @return An array of pointers of type Protocol* describing the protocols adopted
  586. * by the class. Any protocols adopted by superclasses or other protocols are not included.
  587. * The array contains *outCount pointers followed by a NULL terminator. You must free the array with free().
  588. *
  589. * If cls adopts no protocols, or cls is Nil, returns NULL and *outCount is 0.
  590. */
  591. OBJC_EXPORT Protocol * __unsafe_unretained _Nonnull * _Nullable
  592. class_copyProtocolList(Class _Nullable cls, unsigned int * _Nullable outCount)
  593. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  594. /**
  595. * Returns a property with a given name of a given class.
  596. *
  597. * @param cls The class you want to inspect.
  598. * @param name The name of the property you want to inspect.
  599. *
  600. * @return A pointer of type \c objc_property_t describing the property, or
  601. * \c NULL if the class does not declare a property with that name,
  602. * or \c NULL if \e cls is \c Nil.
  603. */
  604. OBJC_EXPORT objc_property_t _Nullable
  605. class_getProperty(Class _Nullable cls, const char * _Nonnull name)
  606. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  607. /**
  608. * Describes the properties declared by a class.
  609. *
  610. * @param cls The class you want to inspect.
  611. * @param outCount On return, contains the length of the returned array.
  612. * If \e outCount is \c NULL, the length is not returned.
  613. *
  614. * @return An array of pointers of type \c objc_property_t describing the properties
  615. * declared by the class. Any properties declared by superclasses are not included.
  616. * The array contains \c *outCount pointers followed by a \c NULL terminator. You must free the array with \c free().
  617. *
  618. * If \e cls declares no properties, or \e cls is \c Nil, returns \c NULL and \c *outCount is \c 0.
  619. */
  620. OBJC_EXPORT objc_property_t _Nonnull * _Nullable
  621. class_copyPropertyList(Class _Nullable cls, unsigned int * _Nullable outCount)
  622. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  623. /**
  624. * Returns a description of the \c Ivar layout for a given class.
  625. *
  626. * @param cls The class to inspect.
  627. *
  628. * @return A description of the \c Ivar layout for \e cls.
  629. */
  630. OBJC_EXPORT const uint8_t * _Nullable
  631. class_getIvarLayout(Class _Nullable cls)
  632. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  633. /**
  634. * Returns a description of the layout of weak Ivars for a given class.
  635. *
  636. * @param cls The class to inspect.
  637. *
  638. * @return A description of the layout of the weak \c Ivars for \e cls.
  639. */
  640. OBJC_EXPORT const uint8_t * _Nullable
  641. class_getWeakIvarLayout(Class _Nullable cls)
  642. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  643. /**
  644. * Adds a new method to a class with a given name and implementation.
  645. *
  646. * @param cls The class to which to add a method.
  647. * @param name A selector that specifies the name of the method being added.
  648. * @param imp A function which is the implementation of the new method. The function must take at least two arguments—self and _cmd.
  649. * @param types An array of characters that describe the types of the arguments to the method.
  650. *
  651. * @return YES if the method was added successfully, otherwise NO
  652. * (for example, the class already contains a method implementation with that name).
  653. *
  654. * @note class_addMethod will add an override of a superclass's implementation,
  655. * but will not replace an existing implementation in this class.
  656. * To change an existing implementation, use method_setImplementation.
  657. */
  658. OBJC_EXPORT BOOL
  659. class_addMethod(Class _Nullable cls, SEL _Nonnull name, IMP _Nonnull imp,
  660. const char * _Nullable types)
  661. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  662. /**
  663. * Replaces the implementation of a method for a given class.
  664. *
  665. * @param cls The class you want to modify.
  666. * @param name A selector that identifies the method whose implementation you want to replace.
  667. * @param imp The new implementation for the method identified by name for the class identified by cls.
  668. * @param types An array of characters that describe the types of the arguments to the method.
  669. * Since the function must take at least two arguments—self and _cmd, the second and third characters
  670. * must be “@:” (the first character is the return type).
  671. *
  672. * @return The previous implementation of the method identified by \e name for the class identified by \e cls.
  673. *
  674. * @note This function behaves in two different ways:
  675. * - If the method identified by \e name does not yet exist, it is added as if \c class_addMethod were called.
  676. * The type encoding specified by \e types is used as given.
  677. * - If the method identified by \e name does exist, its \c IMP is replaced as if \c method_setImplementation were called.
  678. * The type encoding specified by \e types is ignored.
  679. */
  680. OBJC_EXPORT IMP _Nullable
  681. class_replaceMethod(Class _Nullable cls, SEL _Nonnull name, IMP _Nonnull imp,
  682. const char * _Nullable types)
  683. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  684. /**
  685. * Adds a new instance variable to a class.
  686. *
  687. * @return YES if the instance variable was added successfully, otherwise NO
  688. * (for example, the class already contains an instance variable with that name).
  689. *
  690. * @note This function may only be called after objc_allocateClassPair and before objc_registerClassPair.
  691. * Adding an instance variable to an existing class is not supported.
  692. * @note The class must not be a metaclass. Adding an instance variable to a metaclass is not supported.
  693. * @note The instance variable's minimum alignment in bytes is 1<<align. The minimum alignment of an instance
  694. * variable depends on the ivar's type and the machine architecture.
  695. * For variables of any pointer type, pass log2(sizeof(pointer_type)).
  696. */
  697. OBJC_EXPORT BOOL
  698. class_addIvar(Class _Nullable cls, const char * _Nonnull name, size_t size,
  699. uint8_t alignment, const char * _Nullable types)
  700. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  701. /**
  702. * Adds a protocol to a class.
  703. *
  704. * @param cls The class to modify.
  705. * @param protocol The protocol to add to \e cls.
  706. *
  707. * @return \c YES if the method was added successfully, otherwise \c NO
  708. * (for example, the class already conforms to that protocol).
  709. */
  710. OBJC_EXPORT BOOL
  711. class_addProtocol(Class _Nullable cls, Protocol * _Nonnull protocol)
  712. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  713. /**
  714. * Adds a property to a class.
  715. *
  716. * @param cls The class to modify.
  717. * @param name The name of the property.
  718. * @param attributes An array of property attributes.
  719. * @param attributeCount The number of attributes in \e attributes.
  720. *
  721. * @return \c YES if the property was added successfully, otherwise \c NO
  722. * (for example, the class already has that property).
  723. */
  724. OBJC_EXPORT BOOL
  725. class_addProperty(Class _Nullable cls, const char * _Nonnull name,
  726. const objc_property_attribute_t * _Nullable attributes,
  727. unsigned int attributeCount)
  728. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  729. /**
  730. * Replace a property of a class.
  731. *
  732. * @param cls The class to modify.
  733. * @param name The name of the property.
  734. * @param attributes An array of property attributes.
  735. * @param attributeCount The number of attributes in \e attributes.
  736. */
  737. OBJC_EXPORT void
  738. class_replaceProperty(Class _Nullable cls, const char * _Nonnull name,
  739. const objc_property_attribute_t * _Nullable attributes,
  740. unsigned int attributeCount)
  741. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  742. /**
  743. * Sets the Ivar layout for a given class.
  744. *
  745. * @param cls The class to modify.
  746. * @param layout The layout of the \c Ivars for \e cls.
  747. */
  748. OBJC_EXPORT void
  749. class_setIvarLayout(Class _Nullable cls, const uint8_t * _Nullable layout)
  750. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  751. /**
  752. * Sets the layout for weak Ivars for a given class.
  753. *
  754. * @param cls The class to modify.
  755. * @param layout The layout of the weak Ivars for \e cls.
  756. */
  757. OBJC_EXPORT void
  758. class_setWeakIvarLayout(Class _Nullable cls, const uint8_t * _Nullable layout)
  759. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  760. /**
  761. * Used by CoreFoundation's toll-free bridging.
  762. * Return the id of the named class.
  763. *
  764. * @return The id of the named class, or an uninitialized class
  765. * structure that will be used for the class when and if it does
  766. * get loaded.
  767. *
  768. * @warning Do not call this function yourself.
  769. */
  770. OBJC_EXPORT Class _Nonnull
  771. objc_getFutureClass(const char * _Nonnull name)
  772. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0)
  773. OBJC_ARC_UNAVAILABLE;
  774. /* Instantiating Classes */
  775. /**
  776. * Creates an instance of a class, allocating memory for the class in the
  777. * default malloc memory zone.
  778. *
  779. * @param cls The class that you wish to allocate an instance of.
  780. * @param extraBytes An integer indicating the number of extra bytes to allocate.
  781. * The additional bytes can be used to store additional instance variables beyond
  782. * those defined in the class definition.
  783. *
  784. * @return An instance of the class \e cls.
  785. */
  786. OBJC_EXPORT id _Nullable
  787. class_createInstance(Class _Nullable cls, size_t extraBytes)
  788. OBJC_RETURNS_RETAINED
  789. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  790. /**
  791. * Creates an instance of a class at the specific location provided.
  792. *
  793. * @param cls The class that you wish to allocate an instance of.
  794. * @param bytes The location at which to allocate an instance of \e cls.
  795. * Must point to at least \c class_getInstanceSize(cls) bytes of well-aligned,
  796. * zero-filled memory.
  797. *
  798. * @return \e bytes on success, \c nil otherwise. (For example, \e cls or \e bytes
  799. * might be \c nil)
  800. *
  801. * @see class_createInstance
  802. */
  803. OBJC_EXPORT id _Nullable
  804. objc_constructInstance(Class _Nullable cls, void * _Nullable bytes)
  805. OBJC_AVAILABLE(10.6, 3.0, 9.0, 1.0, 2.0)
  806. OBJC_ARC_UNAVAILABLE;
  807. /**
  808. * Destroys an instance of a class without freeing memory and removes any
  809. * associated references this instance might have had.
  810. *
  811. * @param obj The class instance to destroy.
  812. *
  813. * @return \e obj. Does nothing if \e obj is nil.
  814. *
  815. * @note CF and other clients do call this under GC.
  816. */
  817. OBJC_EXPORT void * _Nullable objc_destructInstance(id _Nullable obj)
  818. OBJC_AVAILABLE(10.6, 3.0, 9.0, 1.0, 2.0)
  819. OBJC_ARC_UNAVAILABLE;
  820. /* Adding Classes */
  821. /**
  822. * Creates a new class and metaclass.
  823. *
  824. * @param superclass The class to use as the new class's superclass, or \c Nil to create a new root class.
  825. * @param name The string to use as the new class's name. The string will be copied.
  826. * @param extraBytes The number of bytes to allocate for indexed ivars at the end of
  827. * the class and metaclass objects. This should usually be \c 0.
  828. *
  829. * @return The new class, or Nil if the class could not be created (for example, the desired name is already in use).
  830. *
  831. * @note You can get a pointer to the new metaclass by calling \c object_getClass(newClass).
  832. * @note To create a new class, start by calling \c objc_allocateClassPair.
  833. * Then set the class's attributes with functions like \c class_addMethod and \c class_addIvar.
  834. * When you are done building the class, call \c objc_registerClassPair. The new class is now ready for use.
  835. * @note Instance methods and instance variables should be added to the class itself.
  836. * Class methods should be added to the metaclass.
  837. */
  838. OBJC_EXPORT Class _Nullable
  839. objc_allocateClassPair(Class _Nullable superclass, const char * _Nonnull name,
  840. size_t extraBytes)
  841. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  842. /**
  843. * Registers a class that was allocated using \c objc_allocateClassPair.
  844. *
  845. * @param cls The class you want to register.
  846. */
  847. OBJC_EXPORT void
  848. objc_registerClassPair(Class _Nonnull cls)
  849. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  850. /**
  851. * Used by Foundation's Key-Value Observing.
  852. *
  853. * @warning Do not call this function yourself.
  854. */
  855. OBJC_EXPORT Class _Nonnull
  856. objc_duplicateClass(Class _Nonnull original, const char * _Nonnull name,
  857. size_t extraBytes)
  858. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  859. /**
  860. * Destroy a class and its associated metaclass.
  861. *
  862. * @param cls The class to be destroyed. It must have been allocated with
  863. * \c objc_allocateClassPair
  864. *
  865. * @warning Do not call if instances of this class or a subclass exist.
  866. */
  867. OBJC_EXPORT void
  868. objc_disposeClassPair(Class _Nonnull cls)
  869. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  870. /* Working with Methods */
  871. /**
  872. * Returns the name of a method.
  873. *
  874. * @param m The method to inspect.
  875. *
  876. * @return A pointer of type SEL.
  877. *
  878. * @note To get the method name as a C string, call \c sel_getName(method_getName(method)).
  879. */
  880. OBJC_EXPORT SEL _Nonnull
  881. method_getName(Method _Nonnull m)
  882. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  883. /**
  884. * Returns the implementation of a method.
  885. *
  886. * @param m The method to inspect.
  887. *
  888. * @return A function pointer of type IMP.
  889. */
  890. OBJC_EXPORT IMP _Nonnull
  891. method_getImplementation(Method _Nonnull m)
  892. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  893. /**
  894. * Returns a string describing a method's parameter and return types.
  895. *
  896. * @param m The method to inspect.
  897. *
  898. * @return A C string. The string may be \c NULL.
  899. */
  900. OBJC_EXPORT const char * _Nullable
  901. method_getTypeEncoding(Method _Nonnull m)
  902. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  903. /**
  904. * Returns the number of arguments accepted by a method.
  905. *
  906. * @param m A pointer to a \c Method data structure. Pass the method in question.
  907. *
  908. * @return An integer containing the number of arguments accepted by the given method.
  909. */
  910. OBJC_EXPORT unsigned int
  911. method_getNumberOfArguments(Method _Nonnull m)
  912. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  913. /**
  914. * Returns a string describing a method's return type.
  915. *
  916. * @param m The method to inspect.
  917. *
  918. * @return A C string describing the return type. You must free the string with \c free().
  919. */
  920. OBJC_EXPORT char * _Nonnull
  921. method_copyReturnType(Method _Nonnull m)
  922. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  923. /**
  924. * Returns a string describing a single parameter type of a method.
  925. *
  926. * @param m The method to inspect.
  927. * @param index The index of the parameter to inspect.
  928. *
  929. * @return A C string describing the type of the parameter at index \e index, or \c NULL
  930. * if method has no parameter index \e index. You must free the string with \c free().
  931. */
  932. OBJC_EXPORT char * _Nullable
  933. method_copyArgumentType(Method _Nonnull m, unsigned int index)
  934. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  935. /**
  936. * Returns by reference a string describing a method's return type.
  937. *
  938. * @param m The method you want to inquire about.
  939. * @param dst The reference string to store the description.
  940. * @param dst_len The maximum number of characters that can be stored in \e dst.
  941. *
  942. * @note The method's return type string is copied to \e dst.
  943. * \e dst is filled as if \c strncpy(dst, parameter_type, dst_len) were called.
  944. */
  945. OBJC_EXPORT void
  946. method_getReturnType(Method _Nonnull m, char * _Nonnull dst, size_t dst_len)
  947. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  948. /**
  949. * Returns by reference a string describing a single parameter type of a method.
  950. *
  951. * @param m The method you want to inquire about.
  952. * @param index The index of the parameter you want to inquire about.
  953. * @param dst The reference string to store the description.
  954. * @param dst_len The maximum number of characters that can be stored in \e dst.
  955. *
  956. * @note The parameter type string is copied to \e dst. \e dst is filled as if \c strncpy(dst, parameter_type, dst_len)
  957. * were called. If the method contains no parameter with that index, \e dst is filled as
  958. * if \c strncpy(dst, "", dst_len) were called.
  959. */
  960. OBJC_EXPORT void
  961. method_getArgumentType(Method _Nonnull m, unsigned int index,
  962. char * _Nullable dst, size_t dst_len)
  963. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  964. OBJC_EXPORT struct objc_method_description * _Nonnull
  965. method_getDescription(Method _Nonnull m)
  966. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  967. /**
  968. * Sets the implementation of a method.
  969. *
  970. * @param m The method for which to set an implementation.
  971. * @param imp The implemention to set to this method.
  972. *
  973. * @return The previous implementation of the method.
  974. */
  975. OBJC_EXPORT IMP _Nonnull
  976. method_setImplementation(Method _Nonnull m, IMP _Nonnull imp)
  977. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  978. /**
  979. * Exchanges the implementations of two methods.
  980. *
  981. * @param m1 Method to exchange with second method.
  982. * @param m2 Method to exchange with first method.
  983. *
  984. * @note This is an atomic version of the following:
  985. * \code
  986. * IMP imp1 = method_getImplementation(m1);
  987. * IMP imp2 = method_getImplementation(m2);
  988. * method_setImplementation(m1, imp2);
  989. * method_setImplementation(m2, imp1);
  990. * \endcode
  991. */
  992. OBJC_EXPORT void
  993. method_exchangeImplementations(Method _Nonnull m1, Method _Nonnull m2)
  994. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  995. /* Working with Instance Variables */
  996. /**
  997. * Returns the name of an instance variable.
  998. *
  999. * @param v The instance variable you want to enquire about.
  1000. *
  1001. * @return A C string containing the instance variable's name.
  1002. */
  1003. OBJC_EXPORT const char * _Nullable
  1004. ivar_getName(Ivar _Nonnull v)
  1005. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1006. /**
  1007. * Returns the type string of an instance variable.
  1008. *
  1009. * @param v The instance variable you want to enquire about.
  1010. *
  1011. * @return A C string containing the instance variable's type encoding.
  1012. *
  1013. * @note For possible values, see Objective-C Runtime Programming Guide > Type Encodings.
  1014. */
  1015. OBJC_EXPORT const char * _Nullable
  1016. ivar_getTypeEncoding(Ivar _Nonnull v)
  1017. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1018. /**
  1019. * Returns the offset of an instance variable.
  1020. *
  1021. * @param v The instance variable you want to enquire about.
  1022. *
  1023. * @return The offset of \e v.
  1024. *
  1025. * @note For instance variables of type \c id or other object types, call \c object_getIvar
  1026. * and \c object_setIvar instead of using this offset to access the instance variable data directly.
  1027. */
  1028. OBJC_EXPORT ptrdiff_t
  1029. ivar_getOffset(Ivar _Nonnull v)
  1030. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1031. /* Working with Properties */
  1032. /**
  1033. * Returns the name of a property.
  1034. *
  1035. * @param property The property you want to inquire about.
  1036. *
  1037. * @return A C string containing the property's name.
  1038. */
  1039. OBJC_EXPORT const char * _Nonnull
  1040. property_getName(objc_property_t _Nonnull property)
  1041. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1042. /**
  1043. * Returns the attribute string of a property.
  1044. *
  1045. * @param property A property.
  1046. *
  1047. * @return A C string containing the property's attributes.
  1048. *
  1049. * @note The format of the attribute string is described in Declared Properties in Objective-C Runtime Programming Guide.
  1050. */
  1051. OBJC_EXPORT const char * _Nullable
  1052. property_getAttributes(objc_property_t _Nonnull property)
  1053. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1054. /**
  1055. * Returns an array of property attributes for a property.
  1056. *
  1057. * @param property The property whose attributes you want copied.
  1058. * @param outCount The number of attributes returned in the array.
  1059. *
  1060. * @return An array of property attributes; must be free'd() by the caller.
  1061. */
  1062. OBJC_EXPORT objc_property_attribute_t * _Nullable
  1063. property_copyAttributeList(objc_property_t _Nonnull property,
  1064. unsigned int * _Nullable outCount)
  1065. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  1066. /**
  1067. * Returns the value of a property attribute given the attribute name.
  1068. *
  1069. * @param property The property whose attribute value you are interested in.
  1070. * @param attributeName C string representing the attribute name.
  1071. *
  1072. * @return The value string of the attribute \e attributeName if it exists in
  1073. * \e property, \c nil otherwise.
  1074. */
  1075. OBJC_EXPORT char * _Nullable
  1076. property_copyAttributeValue(objc_property_t _Nonnull property,
  1077. const char * _Nonnull attributeName)
  1078. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  1079. /* Working with Protocols */
  1080. /**
  1081. * Returns a specified protocol.
  1082. *
  1083. * @param name The name of a protocol.
  1084. *
  1085. * @return The protocol named \e name, or \c NULL if no protocol named \e name could be found.
  1086. *
  1087. * @note This function acquires the runtime lock.
  1088. */
  1089. OBJC_EXPORT Protocol * _Nullable
  1090. objc_getProtocol(const char * _Nonnull name)
  1091. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1092. /**
  1093. * Returns an array of all the protocols known to the runtime.
  1094. *
  1095. * @param outCount Upon return, contains the number of protocols in the returned array.
  1096. *
  1097. * @return A C array of all the protocols known to the runtime. The array contains \c *outCount
  1098. * pointers followed by a \c NULL terminator. You must free the list with \c free().
  1099. *
  1100. * @note This function acquires the runtime lock.
  1101. */
  1102. OBJC_EXPORT Protocol * __unsafe_unretained _Nonnull * _Nullable
  1103. objc_copyProtocolList(unsigned int * _Nullable outCount)
  1104. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1105. /**
  1106. * Returns a Boolean value that indicates whether one protocol conforms to another protocol.
  1107. *
  1108. * @param proto A protocol.
  1109. * @param other A protocol.
  1110. *
  1111. * @return \c YES if \e proto conforms to \e other, otherwise \c NO.
  1112. *
  1113. * @note One protocol can incorporate other protocols using the same syntax
  1114. * that classes use to adopt a protocol:
  1115. * \code
  1116. * @protocol ProtocolName < protocol list >
  1117. * \endcode
  1118. * All the protocols listed between angle brackets are considered part of the ProtocolName protocol.
  1119. */
  1120. OBJC_EXPORT BOOL
  1121. protocol_conformsToProtocol(Protocol * _Nullable proto,
  1122. Protocol * _Nullable other)
  1123. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1124. /**
  1125. * Returns a Boolean value that indicates whether two protocols are equal.
  1126. *
  1127. * @param proto A protocol.
  1128. * @param other A protocol.
  1129. *
  1130. * @return \c YES if \e proto is the same as \e other, otherwise \c NO.
  1131. */
  1132. OBJC_EXPORT BOOL
  1133. protocol_isEqual(Protocol * _Nullable proto, Protocol * _Nullable other)
  1134. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1135. /**
  1136. * Returns the name of a protocol.
  1137. *
  1138. * @param proto A protocol.
  1139. *
  1140. * @return The name of the protocol \e p as a C string.
  1141. */
  1142. OBJC_EXPORT const char * _Nonnull
  1143. protocol_getName(Protocol * _Nonnull proto)
  1144. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1145. /**
  1146. * Returns a method description structure for a specified method of a given protocol.
  1147. *
  1148. * @param proto A protocol.
  1149. * @param aSel A selector.
  1150. * @param isRequiredMethod A Boolean value that indicates whether aSel is a required method.
  1151. * @param isInstanceMethod A Boolean value that indicates whether aSel is an instance method.
  1152. *
  1153. * @return An \c objc_method_description structure that describes the method specified by \e aSel,
  1154. * \e isRequiredMethod, and \e isInstanceMethod for the protocol \e p.
  1155. * If the protocol does not contain the specified method, returns an \c objc_method_description structure
  1156. * with the value \c {NULL, \c NULL}.
  1157. *
  1158. * @note This function recursively searches any protocols that this protocol conforms to.
  1159. */
  1160. OBJC_EXPORT struct objc_method_description
  1161. protocol_getMethodDescription(Protocol * _Nonnull proto, SEL _Nonnull aSel,
  1162. BOOL isRequiredMethod, BOOL isInstanceMethod)
  1163. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1164. /**
  1165. * Returns an array of method descriptions of methods meeting a given specification for a given protocol.
  1166. *
  1167. * @param proto A protocol.
  1168. * @param isRequiredMethod A Boolean value that indicates whether returned methods should
  1169. * be required methods (pass YES to specify required methods).
  1170. * @param isInstanceMethod A Boolean value that indicates whether returned methods should
  1171. * be instance methods (pass YES to specify instance methods).
  1172. * @param outCount Upon return, contains the number of method description structures in the returned array.
  1173. *
  1174. * @return A C array of \c objc_method_description structures containing the names and types of \e p's methods
  1175. * specified by \e isRequiredMethod and \e isInstanceMethod. The array contains \c *outCount pointers followed
  1176. * by a \c NULL terminator. You must free the list with \c free().
  1177. * If the protocol declares no methods that meet the specification, \c NULL is returned and \c *outCount is 0.
  1178. *
  1179. * @note Methods in other protocols adopted by this protocol are not included.
  1180. */
  1181. OBJC_EXPORT struct objc_method_description * _Nullable
  1182. protocol_copyMethodDescriptionList(Protocol * _Nonnull proto,
  1183. BOOL isRequiredMethod,
  1184. BOOL isInstanceMethod,
  1185. unsigned int * _Nullable outCount)
  1186. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1187. /**
  1188. * Returns the specified property of a given protocol.
  1189. *
  1190. * @param proto A protocol.
  1191. * @param name The name of a property.
  1192. * @param isRequiredProperty \c YES searches for a required property, \c NO searches for an optional property.
  1193. * @param isInstanceProperty \c YES searches for an instance property, \c NO searches for a class property.
  1194. *
  1195. * @return The property specified by \e name, \e isRequiredProperty, and \e isInstanceProperty for \e proto,
  1196. * or \c NULL if none of \e proto's properties meets the specification.
  1197. */
  1198. OBJC_EXPORT objc_property_t _Nullable
  1199. protocol_getProperty(Protocol * _Nonnull proto,
  1200. const char * _Nonnull name,
  1201. BOOL isRequiredProperty, BOOL isInstanceProperty)
  1202. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1203. /**
  1204. * Returns an array of the required instance properties declared by a protocol.
  1205. *
  1206. * @note Identical to
  1207. * \code
  1208. * protocol_copyPropertyList2(proto, outCount, YES, YES);
  1209. * \endcode
  1210. */
  1211. OBJC_EXPORT objc_property_t _Nonnull * _Nullable
  1212. protocol_copyPropertyList(Protocol * _Nonnull proto,
  1213. unsigned int * _Nullable outCount)
  1214. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1215. /**
  1216. * Returns an array of properties declared by a protocol.
  1217. *
  1218. * @param proto A protocol.
  1219. * @param outCount Upon return, contains the number of elements in the returned array.
  1220. * @param isRequiredProperty \c YES returns required properties, \c NO returns optional properties.
  1221. * @param isInstanceProperty \c YES returns instance properties, \c NO returns class properties.
  1222. *
  1223. * @return A C array of pointers of type \c objc_property_t describing the properties declared by \e proto.
  1224. * Any properties declared by other protocols adopted by this protocol are not included. The array contains
  1225. * \c *outCount pointers followed by a \c NULL terminator. You must free the array with \c free().
  1226. * If the protocol declares no matching properties, \c NULL is returned and \c *outCount is \c 0.
  1227. */
  1228. OBJC_EXPORT objc_property_t _Nonnull * _Nullable
  1229. protocol_copyPropertyList2(Protocol * _Nonnull proto,
  1230. unsigned int * _Nullable outCount,
  1231. BOOL isRequiredProperty, BOOL isInstanceProperty)
  1232. OBJC_AVAILABLE(10.12, 10.0, 10.0, 3.0, 2.0);
  1233. /**
  1234. * Returns an array of the protocols adopted by a protocol.
  1235. *
  1236. * @param proto A protocol.
  1237. * @param outCount Upon return, contains the number of elements in the returned array.
  1238. *
  1239. * @return A C array of protocols adopted by \e proto. The array contains \e *outCount pointers
  1240. * followed by a \c NULL terminator. You must free the array with \c free().
  1241. * If the protocol adopts no other protocols, \c NULL is returned and \c *outCount is \c 0.
  1242. */
  1243. OBJC_EXPORT Protocol * __unsafe_unretained _Nonnull * _Nullable
  1244. protocol_copyProtocolList(Protocol * _Nonnull proto,
  1245. unsigned int * _Nullable outCount)
  1246. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1247. /**
  1248. * Creates a new protocol instance that cannot be used until registered with
  1249. * \c objc_registerProtocol()
  1250. *
  1251. * @param name The name of the protocol to create.
  1252. *
  1253. * @return The Protocol instance on success, \c nil if a protocol
  1254. * with the same name already exists.
  1255. * @note There is no dispose method for this.
  1256. */
  1257. OBJC_EXPORT Protocol * _Nullable
  1258. objc_allocateProtocol(const char * _Nonnull name)
  1259. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  1260. /**
  1261. * Registers a newly constructed protocol with the runtime. The protocol
  1262. * will be ready for use and is immutable after this.
  1263. *
  1264. * @param proto The protocol you want to register.
  1265. */
  1266. OBJC_EXPORT void
  1267. objc_registerProtocol(Protocol * _Nonnull proto)
  1268. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  1269. /**
  1270. * Adds a method to a protocol. The protocol must be under construction.
  1271. *
  1272. * @param proto The protocol to add a method to.
  1273. * @param name The name of the method to add.
  1274. * @param types A C string that represents the method signature.
  1275. * @param isRequiredMethod YES if the method is not an optional method.
  1276. * @param isInstanceMethod YES if the method is an instance method.
  1277. */
  1278. OBJC_EXPORT void
  1279. protocol_addMethodDescription(Protocol * _Nonnull proto, SEL _Nonnull name,
  1280. const char * _Nullable types,
  1281. BOOL isRequiredMethod, BOOL isInstanceMethod)
  1282. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  1283. /**
  1284. * Adds an incorporated protocol to another protocol. The protocol being
  1285. * added to must still be under construction, while the additional protocol
  1286. * must be already constructed.
  1287. *
  1288. * @param proto The protocol you want to add to, it must be under construction.
  1289. * @param addition The protocol you want to incorporate into \e proto, it must be registered.
  1290. */
  1291. OBJC_EXPORT void
  1292. protocol_addProtocol(Protocol * _Nonnull proto, Protocol * _Nonnull addition)
  1293. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  1294. /**
  1295. * Adds a property to a protocol. The protocol must be under construction.
  1296. *
  1297. * @param proto The protocol to add a property to.
  1298. * @param name The name of the property.
  1299. * @param attributes An array of property attributes.
  1300. * @param attributeCount The number of attributes in \e attributes.
  1301. * @param isRequiredProperty YES if the property (accessor methods) is not optional.
  1302. * @param isInstanceProperty YES if the property (accessor methods) are instance methods.
  1303. * This is the only case allowed fo a property, as a result, setting this to NO will
  1304. * not add the property to the protocol at all.
  1305. */
  1306. OBJC_EXPORT void
  1307. protocol_addProperty(Protocol * _Nonnull proto, const char * _Nonnull name,
  1308. const objc_property_attribute_t * _Nullable attributes,
  1309. unsigned int attributeCount,
  1310. BOOL isRequiredProperty, BOOL isInstanceProperty)
  1311. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  1312. /* Working with Libraries */
  1313. /**
  1314. * Returns the names of all the loaded Objective-C frameworks and dynamic
  1315. * libraries.
  1316. *
  1317. * @param outCount The number of names returned.
  1318. *
  1319. * @return An array of C strings of names. Must be free()'d by caller.
  1320. */
  1321. OBJC_EXPORT const char * _Nonnull * _Nonnull
  1322. objc_copyImageNames(unsigned int * _Nullable outCount)
  1323. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1324. /**
  1325. * Returns the dynamic library name a class originated from.
  1326. *
  1327. * @param cls The class you are inquiring about.
  1328. *
  1329. * @return The name of the library containing this class.
  1330. */
  1331. OBJC_EXPORT const char * _Nullable
  1332. class_getImageName(Class _Nullable cls)
  1333. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1334. /**
  1335. * Returns the names of all the classes within a library.
  1336. *
  1337. * @param image The library or framework you are inquiring about.
  1338. * @param outCount The number of class names returned.
  1339. *
  1340. * @return An array of C strings representing the class names.
  1341. */
  1342. OBJC_EXPORT const char * _Nonnull * _Nullable
  1343. objc_copyClassNamesForImage(const char * _Nonnull image,
  1344. unsigned int * _Nullable outCount)
  1345. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1346. /* Working with Selectors */
  1347. /**
  1348. * Returns the name of the method specified by a given selector.
  1349. *
  1350. * @param sel A pointer of type \c SEL. Pass the selector whose name you wish to determine.
  1351. *
  1352. * @return A C string indicating the name of the selector.
  1353. */
  1354. OBJC_EXPORT const char * _Nonnull
  1355. sel_getName(SEL _Nonnull sel)
  1356. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  1357. /**
  1358. * Registers a method with the Objective-C runtime system, maps the method
  1359. * name to a selector, and returns the selector value.
  1360. *
  1361. * @param str A pointer to a C string. Pass the name of the method you wish to register.
  1362. *
  1363. * @return A pointer of type SEL specifying the selector for the named method.
  1364. *
  1365. * @note You must register a method name with the Objective-C runtime system to obtain the
  1366. * method’s selector before you can add the method to a class definition. If the method name
  1367. * has already been registered, this function simply returns the selector.
  1368. */
  1369. OBJC_EXPORT SEL _Nonnull
  1370. sel_registerName(const char * _Nonnull str)
  1371. OBJC_AVAILABLE(10.0, 2.0, 9.0, 1.0, 2.0);
  1372. /**
  1373. * Returns a Boolean value that indicates whether two selectors are equal.
  1374. *
  1375. * @param lhs The selector to compare with rhs.
  1376. * @param rhs The selector to compare with lhs.
  1377. *
  1378. * @return \c YES if \e lhs and \e rhs are equal, otherwise \c NO.
  1379. *
  1380. * @note sel_isEqual is equivalent to ==.
  1381. */
  1382. OBJC_EXPORT BOOL
  1383. sel_isEqual(SEL _Nonnull lhs, SEL _Nonnull rhs)
  1384. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1385. /* Objective-C Language Features */
  1386. /**
  1387. * This function is inserted by the compiler when a mutation
  1388. * is detected during a foreach iteration. It gets called
  1389. * when a mutation occurs, and the enumerationMutationHandler
  1390. * is enacted if it is set up. A fatal error occurs if a handler is not set up.
  1391. *
  1392. * @param obj The object being mutated.
  1393. *
  1394. */
  1395. OBJC_EXPORT void
  1396. objc_enumerationMutation(id _Nonnull obj)
  1397. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1398. /**
  1399. * Sets the current mutation handler.
  1400. *
  1401. * @param handler Function pointer to the new mutation handler.
  1402. */
  1403. OBJC_EXPORT void
  1404. objc_setEnumerationMutationHandler(void (*_Nullable handler)(id _Nonnull ))
  1405. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1406. /**
  1407. * Set the function to be called by objc_msgForward.
  1408. *
  1409. * @param fwd Function to be jumped to by objc_msgForward.
  1410. * @param fwd_stret Function to be jumped to by objc_msgForward_stret.
  1411. *
  1412. * @see message.h::_objc_msgForward
  1413. */
  1414. OBJC_EXPORT void
  1415. objc_setForwardHandler(void * _Nonnull fwd, void * _Nonnull fwd_stret)
  1416. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  1417. /**
  1418. * Creates a pointer to a function that will call the block
  1419. * when the method is called.
  1420. *
  1421. * @param block The block that implements this method. Its signature should
  1422. * be: method_return_type ^(id self, method_args...).
  1423. * The selector is not available as a parameter to this block.
  1424. * The block is copied with \c Block_copy().
  1425. *
  1426. * @return The IMP that calls this block. Must be disposed of with
  1427. * \c imp_removeBlock.
  1428. */
  1429. OBJC_EXPORT IMP _Nonnull
  1430. imp_implementationWithBlock(id _Nonnull block)
  1431. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  1432. /**
  1433. * Return the block associated with an IMP that was created using
  1434. * \c imp_implementationWithBlock.
  1435. *
  1436. * @param anImp The IMP that calls this block.
  1437. *
  1438. * @return The block called by \e anImp.
  1439. */
  1440. OBJC_EXPORT id _Nullable
  1441. imp_getBlock(IMP _Nonnull anImp)
  1442. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  1443. /**
  1444. * Disassociates a block from an IMP that was created using
  1445. * \c imp_implementationWithBlock and releases the copy of the
  1446. * block that was created.
  1447. *
  1448. * @param anImp An IMP that was created using \c imp_implementationWithBlock.
  1449. *
  1450. * @return YES if the block was released successfully, NO otherwise.
  1451. * (For example, the block might not have been used to create an IMP previously).
  1452. */
  1453. OBJC_EXPORT BOOL
  1454. imp_removeBlock(IMP _Nonnull anImp)
  1455. OBJC_AVAILABLE(10.7, 4.3, 9.0, 1.0, 2.0);
  1456. /**
  1457. * This loads the object referenced by a weak pointer and returns it, after
  1458. * retaining and autoreleasing the object to ensure that it stays alive
  1459. * long enough for the caller to use it. This function would be used
  1460. * anywhere a __weak variable is used in an expression.
  1461. *
  1462. * @param location The weak pointer address
  1463. *
  1464. * @return The object pointed to by \e location, or \c nil if \e *location is \c nil.
  1465. */
  1466. OBJC_EXPORT id _Nullable
  1467. objc_loadWeak(id _Nullable * _Nonnull location)
  1468. OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
  1469. /**
  1470. * This function stores a new value into a __weak variable. It would
  1471. * be used anywhere a __weak variable is the target of an assignment.
  1472. *
  1473. * @param location The address of the weak pointer itself
  1474. * @param obj The new object this weak ptr should now point to
  1475. *
  1476. * @return The value stored into \e location, i.e. \e obj
  1477. */
  1478. OBJC_EXPORT id _Nullable
  1479. objc_storeWeak(id _Nullable * _Nonnull location, id _Nullable obj)
  1480. OBJC_AVAILABLE(10.7, 5.0, 9.0, 1.0, 2.0);
  1481. /* Associative References */
  1482. /**
  1483. * Policies related to associative references.
  1484. * These are options to objc_setAssociatedObject()
  1485. */
  1486. typedef OBJC_ENUM(uintptr_t, objc_AssociationPolicy) {
  1487. OBJC_ASSOCIATION_ASSIGN = 0, /**< Specifies a weak reference to the associated object. */
  1488. OBJC_ASSOCIATION_RETAIN_NONATOMIC = 1, /**< Specifies a strong reference to the associated object.
  1489. * The association is not made atomically. */
  1490. OBJC_ASSOCIATION_COPY_NONATOMIC = 3, /**< Specifies that the associated object is copied.
  1491. * The association is not made atomically. */
  1492. OBJC_ASSOCIATION_RETAIN = 01401, /**< Specifies a strong reference to the associated object.
  1493. * The association is made atomically. */
  1494. OBJC_ASSOCIATION_COPY = 01403 /**< Specifies that the associated object is copied.
  1495. * The association is made atomically. */
  1496. };
  1497. /**
  1498. * Sets an associated value for a given object using a given key and association policy.
  1499. *
  1500. * @param object The source object for the association.
  1501. * @param key The key for the association.
  1502. * @param value The value to associate with the key key for object. Pass nil to clear an existing association.
  1503. * @param policy The policy for the association. For possible values, see “Associative Object Behaviors.”
  1504. *
  1505. * @see objc_setAssociatedObject
  1506. * @see objc_removeAssociatedObjects
  1507. */
  1508. OBJC_EXPORT void
  1509. objc_setAssociatedObject(id _Nonnull object, const void * _Nonnull key,
  1510. id _Nullable value, objc_AssociationPolicy policy)
  1511. OBJC_AVAILABLE(10.6, 3.1, 9.0, 1.0, 2.0);
  1512. /**
  1513. * Returns the value associated with a given object for a given key.
  1514. *
  1515. * @param object The source object for the association.
  1516. * @param key The key for the association.
  1517. *
  1518. * @return The value associated with the key \e key for \e object.
  1519. *
  1520. * @see objc_setAssociatedObject
  1521. */
  1522. OBJC_EXPORT id _Nullable
  1523. objc_getAssociatedObject(id _Nonnull object, const void * _Nonnull key)
  1524. OBJC_AVAILABLE(10.6, 3.1, 9.0, 1.0, 2.0);
  1525. /**
  1526. * Removes all associations for a given object.
  1527. *
  1528. * @param object An object that maintains associated objects.
  1529. *
  1530. * @note The main purpose of this function is to make it easy to return an object
  1531. * to a "pristine state”. You should not use this function for general removal of
  1532. * associations from objects, since it also removes associations that other clients
  1533. * may have added to the object. Typically you should use \c objc_setAssociatedObject
  1534. * with a nil value to clear an association.
  1535. *
  1536. * @see objc_setAssociatedObject
  1537. * @see objc_getAssociatedObject
  1538. */
  1539. OBJC_EXPORT void
  1540. objc_removeAssociatedObjects(id _Nonnull object)
  1541. OBJC_AVAILABLE(10.6, 3.1, 9.0, 1.0, 2.0);
  1542. /* Hooks for Swift */
  1543. /**
  1544. * Function type for a hook that intercepts class_getImageName().
  1545. *
  1546. * @param cls The class whose image name is being looked up.
  1547. * @param outImageName On return, the result of the image name lookup.
  1548. * @return YES if an image name for this class was found, NO otherwise.
  1549. *
  1550. * @see class_getImageName
  1551. * @see objc_setHook_getImageName
  1552. */
  1553. typedef BOOL (*objc_hook_getImageName)(Class _Nonnull cls, const char * _Nullable * _Nonnull outImageName);
  1554. /**
  1555. * Install a hook for class_getImageName().
  1556. *
  1557. * @param newValue The hook function to install.
  1558. * @param outOldValue The address of a function pointer variable. On return,
  1559. * the old hook function is stored in the variable.
  1560. *
  1561. * @note The store to *outOldValue is thread-safe: the variable will be
  1562. * updated before class_getImageName() calls your new hook to read it,
  1563. * even if your new hook is called from another thread before this
  1564. * setter completes.
  1565. * @note The first hook in the chain is the native implementation of
  1566. * class_getImageName(). Your hook should call the previous hook for
  1567. * classes that you do not recognize.
  1568. *
  1569. * @see class_getImageName
  1570. * @see objc_hook_getImageName
  1571. */
  1572. OBJC_EXPORT void objc_setHook_getImageName(objc_hook_getImageName _Nonnull newValue,
  1573. objc_hook_getImageName _Nullable * _Nonnull outOldValue)
  1574. OBJC_AVAILABLE(10.14, 12.0, 12.0, 5.0, 3.0);
  1575. /**
  1576. * Function type for a hook that assists objc_getClass() and related functions.
  1577. *
  1578. * @param name The class name to look up.
  1579. * @param outClass On return, the result of the class lookup.
  1580. * @return YES if a class with this name was found, NO otherwise.
  1581. *
  1582. * @see objc_getClass
  1583. * @see objc_setHook_getClass
  1584. */
  1585. typedef BOOL (*objc_hook_getClass)(const char * _Nonnull name, Class _Nullable * _Nonnull outClass);
  1586. /**
  1587. * Install a hook for objc_getClass() and related functions.
  1588. *
  1589. * @param newValue The hook function to install.
  1590. * @param outOldValue The address of a function pointer variable. On return,
  1591. * the old hook function is stored in the variable.
  1592. *
  1593. * @note The store to *outOldValue is thread-safe: the variable will be
  1594. * updated before objc_getClass() calls your new hook to read it,
  1595. * even if your new hook is called from another thread before this
  1596. * setter completes.
  1597. * @note Your hook should call the previous hook for class names
  1598. * that you do not recognize.
  1599. *
  1600. * @see objc_getClass
  1601. * @see objc_hook_getClass
  1602. */
  1603. #if !(TARGET_OS_OSX && __i386__)
  1604. #define OBJC_GETCLASSHOOK_DEFINED 1
  1605. OBJC_EXPORT void objc_setHook_getClass(objc_hook_getClass _Nonnull newValue,
  1606. objc_hook_getClass _Nullable * _Nonnull outOldValue)
  1607. OBJC_AVAILABLE(10.14.4, 12.2, 12.2, 5.2, 3.2);
  1608. #endif
  1609. /**
  1610. * Function type for a hook that assists objc_setAssociatedObject().
  1611. *
  1612. * @param object The source object for the association.
  1613. * @param key The key for the association.
  1614. * @param value The value to associate with the key key for object. Pass nil to clear an existing association.
  1615. * @param policy The policy for the association. For possible values, see “Associative Object Behaviors.”
  1616. *
  1617. * @see objc_setAssociatedObject
  1618. * @see objc_setHook_setAssociatedObject
  1619. */
  1620. typedef void (*objc_hook_setAssociatedObject)(id _Nonnull object, const void * _Nonnull key,
  1621. id _Nullable value, objc_AssociationPolicy policy);
  1622. /**
  1623. * Install a hook for objc_setAssociatedObject().
  1624. *
  1625. * @param newValue The hook function to install.
  1626. * @param outOldValue The address of a function pointer variable. On return,
  1627. * the old hook function is stored in the variable.
  1628. *
  1629. * @note The store to *outOldValue is thread-safe: the variable will be
  1630. * updated before objc_setAssociatedObject() calls your new hook to read it,
  1631. * even if your new hook is called from another thread before this
  1632. * setter completes.
  1633. * @note Your hook should always call the previous hook.
  1634. *
  1635. * @see objc_setAssociatedObject
  1636. * @see objc_hook_setAssociatedObject
  1637. */
  1638. #if !(TARGET_OS_OSX && __i386__)
  1639. #define OBJC_SETASSOCIATEDOBJECTHOOK_DEFINED 1
  1640. OBJC_EXPORT void objc_setHook_setAssociatedObject(objc_hook_setAssociatedObject _Nonnull newValue,
  1641. objc_hook_setAssociatedObject _Nullable * _Nonnull outOldValue)
  1642. OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 4.0);
  1643. #endif
  1644. /**
  1645. * Function type for a function that is called when an image is loaded.
  1646. *
  1647. * @param header The newly loaded header.
  1648. */
  1649. struct mach_header;
  1650. typedef void (*objc_func_loadImage)(const struct mach_header * _Nonnull header);
  1651. /**
  1652. * Add a function to be called when a new image is loaded. The function is
  1653. * called after ObjC has scanned and fixed up the image. It is called
  1654. * BEFORE +load methods are invoked.
  1655. *
  1656. * When adding a new function, that function is immediately called with all
  1657. * images that are currently loaded. It is then called as needed for images
  1658. * that are loaded afterwards.
  1659. *
  1660. * Note: the function is called with ObjC's internal runtime lock held.
  1661. * Be VERY careful with what the function does to avoid deadlocks or
  1662. * poor performance.
  1663. *
  1664. * @param func The function to add.
  1665. */
  1666. #define OBJC_ADDLOADIMAGEFUNC_DEFINED 1
  1667. OBJC_EXPORT void objc_addLoadImageFunc(objc_func_loadImage _Nonnull func)
  1668. OBJC_AVAILABLE(10.15, 13.0, 13.0, 6.0, 4.0);
  1669. /**
  1670. * Callback from Objective-C to Swift to perform Swift class initialization.
  1671. */
  1672. #if !(TARGET_OS_OSX && __i386__)
  1673. typedef Class _Nullable
  1674. (*_objc_swiftMetadataInitializer)(Class _Nonnull cls, void * _Nullable arg);
  1675. #endif
  1676. /**
  1677. * Perform Objective-C initialization of a Swift class.
  1678. * Do not call this function. It is provided for the Swift runtime's use only
  1679. * and will change without notice or mercy.
  1680. */
  1681. #if !(TARGET_OS_OSX && __i386__)
  1682. #define OBJC_REALIZECLASSFROMSWIFT_DEFINED 1
  1683. OBJC_EXPORT Class _Nullable
  1684. _objc_realizeClassFromSwift(Class _Nullable cls, void * _Nullable previously)
  1685. OBJC_AVAILABLE(10.14.4, 12.2, 12.2, 5.2, 3.2);
  1686. #endif
  1687. #define _C_ID '@'
  1688. #define _C_CLASS '#'
  1689. #define _C_SEL ':'
  1690. #define _C_CHR 'c'
  1691. #define _C_UCHR 'C'
  1692. #define _C_SHT 's'
  1693. #define _C_USHT 'S'
  1694. #define _C_INT 'i'
  1695. #define _C_UINT 'I'
  1696. #define _C_LNG 'l'
  1697. #define _C_ULNG 'L'
  1698. #define _C_LNG_LNG 'q'
  1699. #define _C_ULNG_LNG 'Q'
  1700. #define _C_FLT 'f'
  1701. #define _C_DBL 'd'
  1702. #define _C_BFLD 'b'
  1703. #define _C_BOOL 'B'
  1704. #define _C_VOID 'v'
  1705. #define _C_UNDEF '?'
  1706. #define _C_PTR '^'
  1707. #define _C_CHARPTR '*'
  1708. #define _C_ATOM '%'
  1709. #define _C_ARY_B '['
  1710. #define _C_ARY_E ']'
  1711. #define _C_UNION_B '('
  1712. #define _C_UNION_E ')'
  1713. #define _C_STRUCT_B '{'
  1714. #define _C_STRUCT_E '}'
  1715. #define _C_VECTOR '!'
  1716. #define _C_CONST 'r'
  1717. /* Obsolete types */
  1718. #if !__OBJC2__
  1719. #define CLS_GETINFO(cls,infomask) ((cls)->info & (infomask))
  1720. #define CLS_SETINFO(cls,infomask) ((cls)->info |= (infomask))
  1721. // class is not a metaclass
  1722. #define CLS_CLASS 0x1
  1723. // class is a metaclass
  1724. #define CLS_META 0x2
  1725. // class's +initialize method has completed
  1726. #define CLS_INITIALIZED 0x4
  1727. // class is posing
  1728. #define CLS_POSING 0x8
  1729. // unused
  1730. #define CLS_MAPPED 0x10
  1731. // class and subclasses need cache flush during image loading
  1732. #define CLS_FLUSH_CACHE 0x20
  1733. // method cache should grow when full
  1734. #define CLS_GROW_CACHE 0x40
  1735. // unused
  1736. #define CLS_NEED_BIND 0x80
  1737. // methodLists is array of method lists
  1738. #define CLS_METHOD_ARRAY 0x100
  1739. // the JavaBridge constructs classes with these markers
  1740. #define CLS_JAVA_HYBRID 0x200
  1741. #define CLS_JAVA_CLASS 0x400
  1742. // thread-safe +initialize
  1743. #define CLS_INITIALIZING 0x800
  1744. // bundle unloading
  1745. #define CLS_FROM_BUNDLE 0x1000
  1746. // C++ ivar support
  1747. #define CLS_HAS_CXX_STRUCTORS 0x2000
  1748. // Lazy method list arrays
  1749. #define CLS_NO_METHOD_ARRAY 0x4000
  1750. // +load implementation
  1751. #define CLS_HAS_LOAD_METHOD 0x8000
  1752. // objc_allocateClassPair API
  1753. #define CLS_CONSTRUCTING 0x10000
  1754. // class compiled with bigger class structure
  1755. #define CLS_EXT 0x20000
  1756. struct objc_method_description_list {
  1757. int count;
  1758. struct objc_method_description list[1];
  1759. };
  1760. struct objc_protocol_list {
  1761. struct objc_protocol_list * _Nullable next;
  1762. long count;
  1763. __unsafe_unretained Protocol * _Nullable list[1];
  1764. };
  1765. struct objc_category {
  1766. char * _Nonnull category_name OBJC2_UNAVAILABLE;
  1767. char * _Nonnull class_name OBJC2_UNAVAILABLE;
  1768. struct objc_method_list * _Nullable instance_methods OBJC2_UNAVAILABLE;
  1769. struct objc_method_list * _Nullable class_methods OBJC2_UNAVAILABLE;
  1770. struct objc_protocol_list * _Nullable protocols OBJC2_UNAVAILABLE;
  1771. } OBJC2_UNAVAILABLE;
  1772. struct objc_ivar {
  1773. char * _Nullable ivar_name OBJC2_UNAVAILABLE;
  1774. char * _Nullable ivar_type OBJC2_UNAVAILABLE;
  1775. int ivar_offset OBJC2_UNAVAILABLE;
  1776. #ifdef __LP64__
  1777. int space OBJC2_UNAVAILABLE;
  1778. #endif
  1779. } OBJC2_UNAVAILABLE;
  1780. struct objc_ivar_list {
  1781. int ivar_count OBJC2_UNAVAILABLE;
  1782. #ifdef __LP64__
  1783. int space OBJC2_UNAVAILABLE;
  1784. #endif
  1785. /* variable length structure */
  1786. struct objc_ivar ivar_list[1] OBJC2_UNAVAILABLE;
  1787. } OBJC2_UNAVAILABLE;
  1788. struct objc_method {
  1789. SEL _Nonnull method_name OBJC2_UNAVAILABLE;
  1790. char * _Nullable method_types OBJC2_UNAVAILABLE;
  1791. IMP _Nonnull method_imp OBJC2_UNAVAILABLE;
  1792. } OBJC2_UNAVAILABLE;
  1793. struct objc_method_list {
  1794. struct objc_method_list * _Nullable obsolete OBJC2_UNAVAILABLE;
  1795. int method_count OBJC2_UNAVAILABLE;
  1796. #ifdef __LP64__
  1797. int space OBJC2_UNAVAILABLE;
  1798. #endif
  1799. /* variable length structure */
  1800. struct objc_method method_list[1] OBJC2_UNAVAILABLE;
  1801. } OBJC2_UNAVAILABLE;
  1802. typedef struct objc_symtab *Symtab OBJC2_UNAVAILABLE;
  1803. struct objc_symtab {
  1804. unsigned long sel_ref_cnt OBJC2_UNAVAILABLE;
  1805. SEL _Nonnull * _Nullable refs OBJC2_UNAVAILABLE;
  1806. unsigned short cls_def_cnt OBJC2_UNAVAILABLE;
  1807. unsigned short cat_def_cnt OBJC2_UNAVAILABLE;
  1808. void * _Nullable defs[1] /* variable size */ OBJC2_UNAVAILABLE;
  1809. } OBJC2_UNAVAILABLE;
  1810. typedef struct objc_cache *Cache OBJC2_UNAVAILABLE;
  1811. #define CACHE_BUCKET_NAME(B) ((B)->method_name)
  1812. #define CACHE_BUCKET_IMP(B) ((B)->method_imp)
  1813. #define CACHE_BUCKET_VALID(B) (B)
  1814. #ifndef __LP64__
  1815. #define CACHE_HASH(sel, mask) (((uintptr_t)(sel)>>2) & (mask))
  1816. #else
  1817. #define CACHE_HASH(sel, mask) (((unsigned int)((uintptr_t)(sel)>>3)) & (mask))
  1818. #endif
  1819. struct objc_cache {
  1820. unsigned int mask /* total = mask + 1 */ OBJC2_UNAVAILABLE;
  1821. unsigned int occupied OBJC2_UNAVAILABLE;
  1822. Method _Nullable buckets[1] OBJC2_UNAVAILABLE;
  1823. };
  1824. typedef struct objc_module *Module OBJC2_UNAVAILABLE;
  1825. struct objc_module {
  1826. unsigned long version OBJC2_UNAVAILABLE;
  1827. unsigned long size OBJC2_UNAVAILABLE;
  1828. const char * _Nullable name OBJC2_UNAVAILABLE;
  1829. Symtab _Nullable symtab OBJC2_UNAVAILABLE;
  1830. } OBJC2_UNAVAILABLE;
  1831. #else
  1832. struct objc_method_list;
  1833. #endif
  1834. /* Obsolete functions */
  1835. OBJC_EXPORT IMP _Nullable
  1836. class_lookupMethod(Class _Nullable cls, SEL _Nonnull sel)
  1837. __OSX_DEPRECATED(10.0, 10.5, "use class_getMethodImplementation instead")
  1838. __IOS_DEPRECATED(2.0, 2.0, "use class_getMethodImplementation instead")
  1839. __TVOS_DEPRECATED(9.0, 9.0, "use class_getMethodImplementation instead")
  1840. __WATCHOS_DEPRECATED(1.0, 1.0, "use class_getMethodImplementation instead")
  1841. #ifndef __APPLE_BLEACH_SDK__
  1842. __BRIDGEOS_DEPRECATED(2.0, 2.0, "use class_getMethodImplementation instead")
  1843. #endif
  1844. ;
  1845. OBJC_EXPORT BOOL
  1846. class_respondsToMethod(Class _Nullable cls, SEL _Nonnull sel)
  1847. __OSX_DEPRECATED(10.0, 10.5, "use class_respondsToSelector instead")
  1848. __IOS_DEPRECATED(2.0, 2.0, "use class_respondsToSelector instead")
  1849. __TVOS_DEPRECATED(9.0, 9.0, "use class_respondsToSelector instead")
  1850. __WATCHOS_DEPRECATED(1.0, 1.0, "use class_respondsToSelector instead")
  1851. #ifndef __APPLE_BLEACH_SDK__
  1852. __BRIDGEOS_DEPRECATED(2.0, 2.0, "use class_respondsToSelector instead")
  1853. #endif
  1854. ;
  1855. OBJC_EXPORT void
  1856. _objc_flush_caches(Class _Nullable cls)
  1857. __OSX_DEPRECATED(10.0, 10.5, "not recommended")
  1858. __IOS_DEPRECATED(2.0, 2.0, "not recommended")
  1859. __TVOS_DEPRECATED(9.0, 9.0, "not recommended")
  1860. __WATCHOS_DEPRECATED(1.0, 1.0, "not recommended")
  1861. #ifndef __APPLE_BLEACH_SDK__
  1862. __BRIDGEOS_DEPRECATED(2.0, 2.0, "not recommended")
  1863. #endif
  1864. ;
  1865. OBJC_EXPORT id _Nullable
  1866. object_copyFromZone(id _Nullable anObject, size_t nBytes, void * _Nullable z)
  1867. OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE(10.0, 10.5, "use object_copy instead");
  1868. OBJC_EXPORT id _Nullable
  1869. object_realloc(id _Nullable anObject, size_t nBytes)
  1870. OBJC2_UNAVAILABLE;
  1871. OBJC_EXPORT id _Nullable
  1872. object_reallocFromZone(id _Nullable anObject, size_t nBytes, void * _Nullable z)
  1873. OBJC2_UNAVAILABLE;
  1874. #define OBSOLETE_OBJC_GETCLASSES 1
  1875. OBJC_EXPORT void * _Nonnull
  1876. objc_getClasses(void)
  1877. OBJC2_UNAVAILABLE;
  1878. OBJC_EXPORT void
  1879. objc_addClass(Class _Nonnull myClass)
  1880. OBJC2_UNAVAILABLE;
  1881. OBJC_EXPORT void
  1882. objc_setClassHandler(int (* _Nullable )(const char * _Nonnull))
  1883. OBJC2_UNAVAILABLE;
  1884. OBJC_EXPORT void
  1885. objc_setMultithreaded(BOOL flag)
  1886. OBJC2_UNAVAILABLE;
  1887. OBJC_EXPORT id _Nullable
  1888. class_createInstanceFromZone(Class _Nullable, size_t idxIvars,
  1889. void * _Nullable z)
  1890. OBJC_OSX_DEPRECATED_OTHERS_UNAVAILABLE(10.0, 10.5, "use class_createInstance instead");
  1891. OBJC_EXPORT void
  1892. class_addMethods(Class _Nullable, struct objc_method_list * _Nonnull)
  1893. OBJC2_UNAVAILABLE;
  1894. OBJC_EXPORT void
  1895. class_removeMethods(Class _Nullable, struct objc_method_list * _Nonnull)
  1896. OBJC2_UNAVAILABLE;
  1897. OBJC_EXPORT void
  1898. _objc_resolve_categories_for_class(Class _Nonnull cls)
  1899. OBJC2_UNAVAILABLE;
  1900. OBJC_EXPORT Class _Nonnull
  1901. class_poseAs(Class _Nonnull imposter, Class _Nonnull original)
  1902. OBJC2_UNAVAILABLE;
  1903. OBJC_EXPORT unsigned int
  1904. method_getSizeOfArguments(Method _Nonnull m)
  1905. OBJC2_UNAVAILABLE;
  1906. OBJC_EXPORT unsigned
  1907. method_getArgumentInfo(struct objc_method * _Nonnull m, int arg,
  1908. const char * _Nullable * _Nonnull type,
  1909. int * _Nonnull offset)
  1910. UNAVAILABLE_ATTRIBUTE // This function was accidentally deleted in 10.9.
  1911. OBJC2_UNAVAILABLE;
  1912. OBJC_EXPORT Class _Nullable
  1913. objc_getOrigClass(const char * _Nonnull name)
  1914. OBJC2_UNAVAILABLE;
  1915. #define OBJC_NEXT_METHOD_LIST 1
  1916. OBJC_EXPORT struct objc_method_list * _Nullable
  1917. class_nextMethodList(Class _Nullable, void * _Nullable * _Nullable)
  1918. OBJC2_UNAVAILABLE;
  1919. // usage for nextMethodList
  1920. //
  1921. // void *iterator = 0;
  1922. // struct objc_method_list *mlist;
  1923. // while ( mlist = class_nextMethodList( cls, &iterator ) )
  1924. // ;
  1925. OBJC_EXPORT id _Nullable
  1926. (* _Nonnull _alloc)(Class _Nullable, size_t)
  1927. OBJC2_UNAVAILABLE;
  1928. OBJC_EXPORT id _Nullable
  1929. (* _Nonnull _copy)(id _Nullable, size_t)
  1930. OBJC2_UNAVAILABLE;
  1931. OBJC_EXPORT id _Nullable
  1932. (* _Nonnull _realloc)(id _Nullable, size_t)
  1933. OBJC2_UNAVAILABLE;
  1934. OBJC_EXPORT id _Nullable
  1935. (* _Nonnull _dealloc)(id _Nullable)
  1936. OBJC2_UNAVAILABLE;
  1937. OBJC_EXPORT id _Nullable
  1938. (* _Nonnull _zoneAlloc)(Class _Nullable, size_t, void * _Nullable)
  1939. OBJC2_UNAVAILABLE;
  1940. OBJC_EXPORT id _Nullable
  1941. (* _Nonnull _zoneRealloc)(id _Nullable, size_t, void * _Nullable)
  1942. OBJC2_UNAVAILABLE;
  1943. OBJC_EXPORT id _Nullable
  1944. (* _Nonnull _zoneCopy)(id _Nullable, size_t, void * _Nullable)
  1945. OBJC2_UNAVAILABLE;
  1946. OBJC_EXPORT void
  1947. (* _Nonnull _error)(id _Nullable, const char * _Nonnull, va_list)
  1948. OBJC2_UNAVAILABLE;
  1949. #endif