Function

class_addIvar(_:_:_:_:_:)

Adds a new instance variable to a class.

Declaration

func class_addIvar(_ cls: AnyClass!, _ name: UnsafePointer<Int8>!, _ size: Int, _ alignment: UInt8, _ types: UnsafePointer<Int8>!) -> Bool

Return Value

true if the instance variable was added successfully, otherwise false (for example, the class already contains an instance variable with that name).

Discussion

This function may only be called after objc_allocateClassPair(_:_:_:) and before objc_registerClassPair(_:). Adding an instance variable to an existing class is not supported.

The class must not be a metaclass. Adding an instance variable to a metaclass is not supported.

The instance variable's minimum alignment in bytes is 1<<align. The minimum alignment of an instance variable depends on the ivar's type and the machine architecture. For variables of any pointer type, pass log2(sizeof(pointer_type)).