Function 関数

objc_allocateClassPair

Creates a new class and metaclass. 新しいクラスとメタクラスを作成します。

Declaration 宣言

Class objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes);

Parameters パラメータ

superclass

The class to use as the new class's superclass, or Nil to create a new root class.

name

The string to use as the new class's name. The string will be copied. 新しいクラスの名前として使う文字列。この文字列はコピーされます。

extraBytes

The number of bytes to allocate for indexed ivars at the end of the class and metaclass objects. メタクラスオブジェクトそれらそしてクラスの終わりでのインデックスを付けられたivarそれらに対して割り当てられるバイト数。 This should usually be 0.

Return Value 戻り値

The new class, or Nil if the class could not be created (for example, the desired name is already in use).

Discussion 解説

You can get a pointer to the new metaclass by calling object_getClass(newClass).

To create a new class, start by calling objc_allocateClassPair. Then set the class's attributes with functions like class_addMethod and class_addIvar. When you are done building the class, call objc_registerClassPair. The new class is now ready for use. 新しいクラスは今や使用する準備ができました。

Instance methods and instance variables should be added to the class itself. Class methods should be added to the metaclass. インスタンスメソッドおよびインスタンス変数は、クラスそれ自身に加えられるべきです。クラスメソッドは、メタクラスに加えられるべきです。

See Also 参照

Adding Classes クラスを加える