<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "ObjectiveC",
  "identifier" : "/documentation/ObjectiveC/objc_allocateClassPair(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Objective-C Runtime"
    ],
    "preciseIdentifier" : "c:@F@objc_allocateClassPair"
  },
  "title" : "objc_allocateClassPair(_:_:_:)"
}
-->

# objc_allocateClassPair(_:_:_:)

Creates a new class and metaclass.

```
func objc_allocateClassPair(_ superclass: AnyClass?, _ name: UnsafePointer<CChar>, _ extraBytes: Int) -> AnyClass?
```

## 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. 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(_:_:_:)`](/documentation/ObjectiveC/objc_allocateClassPair(_:_:_:)). Then set the class’s attributes with functions like [`class_addMethod(_:_:_:_:)`](/documentation/ObjectiveC/class_addMethod(_:_:_:_:)) and [`class_addIvar(_:_:_:_:_:)`](/documentation/ObjectiveC/class_addIvar(_:_:_:_:_:)). When you are done building the class, call [`objc_registerClassPair(_:)`](/documentation/ObjectiveC/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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)