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