objc

Modules | Data Structures | Macros | Typedefs | Functions
Objective-C Runtime

Objective-C runtime, providing class introspection, protocols and resolution of selectors to the methods. More...

Collaboration diagram for Objective-C Runtime:

Modules

 Foundation Framework
 Foundational classes and types, including strings, numbers, dates, data and collections.
 
 Application Framework
 Application-related classes and types, including application lifecycle, event handling, display and frames, and hardware interfaces.
 
 Network Framework
 Network-related classes and types, including WiFi adapter management, connection management, data transmission and network protocols.
 

Data Structures

protocol  <NXConstantStringProtocol>
 Protocol for constant string objects. More...
 
class  NXConstantString
 A constant string class. More...
 
protocol  <ObjectProtocol>
 Protocol for objects. More...
 
class  Object
 The root class of all Objective-C classes. More...
 
class  Protocol
 Protocol class definition. More...
 

Macros

#define objc_assert(condition)
 Asserts that a condition is true. More...
 
#define nil   ((id)0)
 A null object pointer.
 
#define Nil   ((Class)0)
 A null class pointer.
 
#define YES   true
 The Boolean value true.
 
#define NO   false
 The Boolean value false.
 
#define OBJC_ROOT_CLASS
 A macro to declare a class as a root class. More...
 
#define OBJC_UNUSED
 A macro to declare a method parameter is unused. More...
 
#define OBJC_REQUIRES_NIL_TERMINATION
 A macro to indicate that a method requires a nil-terminated list of arguments. More...
 

Typedefs

typedef struct objc_object * id
 A pointer to an instance of a class.
 
typedef const struct objc_selector * SEL
 A pointer to a method selector.
 
typedef struct objc_class * Class
 A pointer to a class definition.
 
typedef id(* IMP) (id, SEL,...)
 A pointer to a method implementation.
 
typedef struct objc_method * Method
 A pointer to a method.
 
typedef struct objc_protocol objc_protocol_t
 An instance of a protocol.
 
typedef bool BOOL
 A Boolean value.
 

Functions

void * objc_malloc (size_t size)
 Allocate memory for use by the Objective-C runtime. More...
 
void objc_free (void *ptr)
 Free memory previously allocated by objc_malloc(). More...
 
int objc_sync_enter (id obj)
 Acquire a lock on the specified object for thread synchronization. More...
 
int objc_sync_exit (id obj)
 Release a lock on the specified object. More...
 
Class objc_lookupClass (const char *name)
 Looks up a class by name. More...
 
const char * class_getName (Class cls)
 Returns the name of a class. More...
 
const char * object_getClassName (id obj)
 Returns the name of an object's class. More...
 
Class object_getClass (id object)
 Returns the class of an object. More...
 
void object_setClass (id object, Class cls)
 Sets the class of an object. More...
 
BOOL object_respondsToSelector (id object, SEL sel)
 Checks if an instance's class responds to a selector. More...
 
Class object_getSuperclass (id obj)
 Returns the superclass of an object. More...
 
Class class_getSuperclass (Class cls)
 Returns the superclass of a class. More...
 
BOOL object_isKindOfClass (id object, Class cls)
 Checks if an instance class matches, or subclass of another class. More...
 
size_t class_getInstanceSize (Class cls)
 Returns the size of an instance of a class. More...
 
BOOL class_metaclassRespondsToSelector (Class cls, SEL sel)
 Checks if a class object responds to a selector. More...
 
BOOL class_respondsToSelector (Class cls, SEL sel)
 Checks if an instance of a class responds to a selector. More...
 
const char * sel_getName (SEL sel)
 Returns the name of a selector. More...
 
const char * proto_getName (objc_protocol_t *protocol)
 Returns the name of a protocol. More...
 
BOOL proto_conformsTo (objc_protocol_t *protocol, objc_protocol_t *otherProtocol)
 Checks if a protocol conforms to another protocol. More...
 
BOOL class_conformsTo (Class cls, objc_protocol_t *otherProtocol)
 Checks if a class conforms to a protocol. More...
 

Detailed Description

Objective-C runtime, providing class introspection, protocols and resolution of selectors to the methods.

Macro Definition Documentation

◆ objc_assert

#define objc_assert (   condition)
Value:
if (!(condition)) { \
sys_panicf("ASSERT FAIL: %s", #condition); \
}

Asserts that a condition is true.

Parameters
conditionThe condition to check.

If the DEBUG macro is defined, this macro will check the given condition. If the condition is false, it will call panicf with an assertion failure message, including the condition, file name, and line number. If DEBUG is not defined, this macro does nothing.

Examples:
examples/Application/blink/main.m, and examples/Application/timer/main.m.

Definition at line 29 of file assert.h.

◆ OBJC_REQUIRES_NIL_TERMINATION

#define OBJC_REQUIRES_NIL_TERMINATION

A macro to indicate that a method requires a nil-terminated list of arguments.

This macro is used in method declarations to specify that the method accepts a variable number of arguments that must be terminated with nil.

Definition at line 109 of file runtime.h.

◆ OBJC_ROOT_CLASS

#define OBJC_ROOT_CLASS

A macro to declare a class as a root class.

This macro uses the objc_root_class attribute if it is available, which allows a class to be defined without a superclass.

Definition at line 83 of file runtime.h.

◆ OBJC_UNUSED

#define OBJC_UNUSED

A macro to declare a method parameter is unused.

This macro uses the unused attribute if it is available, which allows a method parameter to be marked as unused.

Definition at line 97 of file runtime.h.

Function Documentation

◆ class_conformsTo()

BOOL class_conformsTo ( Class  cls,
objc_protocol_t otherProtocol 
)

Checks if a class conforms to a protocol.

Parameters
clsThe class to test for conformance.
otherProtocolThe protocol to check conformance against.
Returns
YES if methods of a cls conforms to otherProtocol, NO otherwise.

◆ class_getInstanceSize()

size_t class_getInstanceSize ( Class  cls)

Returns the size of an instance of a class.

Parameters
clsThe class to inspect.
Returns
The size of an instance of the class in bytes, or 0 if the class is Nil.

◆ class_getName()

const char* class_getName ( Class  cls)

Returns the name of a class.

Parameters
clsThe class to inspect.
Returns
A C-string containing the name of the class, or NULL if cls is Nil.

◆ class_getSuperclass()

Class class_getSuperclass ( Class  cls)

Returns the superclass of a class.

Parameters
clsThe class to inspect.
Returns
The superclass of the class, or Nil if it is a root class.

◆ class_metaclassRespondsToSelector()

BOOL class_metaclassRespondsToSelector ( Class  cls,
SEL  sel 
)

Checks if a class object responds to a selector.

Parameters
clsThe class to inspect.
selThe selector to check.
Returns
YES if the class responds to the selector, NO otherwise.

◆ class_respondsToSelector()

BOOL class_respondsToSelector ( Class  cls,
SEL  sel 
)

Checks if an instance of a class responds to a selector.

Parameters
clsThe class to inspect.
selThe selector to check.
Returns
YES if instances of the class respond to the selector, NO otherwise.

◆ objc_free()

void objc_free ( void *  ptr)

Free memory previously allocated by objc_malloc().

Parameters
ptrA pointer to the memory block to be deallocated.

◆ objc_lookupClass()

Class objc_lookupClass ( const char *  name)

Looks up a class by name.

Parameters
nameThe name of the class to look up.
Returns
The class object, or Nil if the class is not found.

◆ objc_malloc()

void* objc_malloc ( size_t  size)

Allocate memory for use by the Objective-C runtime.

Parameters
sizeThe number of bytes to allocate.
Returns
A pointer to the allocated memory block, or NULL if allocation fails.

◆ objc_sync_enter()

int objc_sync_enter ( id  obj)

Acquire a lock on the specified object for thread synchronization.

Parameters
objThe object to lock. Must not be nil.
Returns
0 on success, or a non-zero error code on failure.

◆ objc_sync_exit()

int objc_sync_exit ( id  obj)

Release a lock on the specified object.

Parameters
objThe object to unlock. Must be the same object passed to objc_sync_enter().
Returns
0 on success, or a non-zero error code on failure.

◆ object_getClass()

Class object_getClass ( id  object)

Returns the class of an object.

Parameters
objectThe object to inspect.
Returns
The class of the object, or Nil if the object is nil.

◆ object_getClassName()

const char* object_getClassName ( id  obj)

Returns the name of an object's class.

Parameters
objThe object to inspect.
Returns
A C-string containing the name of the object's class, or NULL if obj is nil.

◆ object_getSuperclass()

Class object_getSuperclass ( id  obj)

Returns the superclass of an object.

Parameters
objThe object to inspect.
Returns
The superclass of the object, or Nil if it is a root class.

◆ object_isKindOfClass()

BOOL object_isKindOfClass ( id  object,
Class  cls 
)

Checks if an instance class matches, or subclass of another class.

Parameters
objectThe object to inspect.
clsThe class to compare against.
Returns
YES if object class matches or is a subclass of cls, NO otherwise.

◆ object_respondsToSelector()

BOOL object_respondsToSelector ( id  object,
SEL  sel 
)

Checks if an instance's class responds to a selector.

Parameters
objectThe object to inspect.
selThe selector to check.
Returns
YES if instances of the class respond to the selector, NO otherwise.

◆ object_setClass()

void object_setClass ( id  object,
Class  cls 
)

Sets the class of an object.

Parameters
objectThe object to modify.
clsThe new class for the object.

◆ proto_conformsTo()

BOOL proto_conformsTo ( objc_protocol_t protocol,
objc_protocol_t otherProtocol 
)

Checks if a protocol conforms to another protocol.

Parameters
protocolThe protocol to test for conformance.
otherProtocolThe protocol to check conformance against.
Returns
YES if protocol conforms to otherProtocol, NO otherwise.

◆ proto_getName()

const char* proto_getName ( objc_protocol_t protocol)

Returns the name of a protocol.

Parameters
protocolThe protocol to inspect.
Returns
A C-string containing the name of the protocol, or NULL if protocol is NULL.

◆ sel_getName()

const char* sel_getName ( SEL  sel)

Returns the name of a selector.

Parameters
selThe selector to inspect.
Returns
A C-string representing the selector's name.