<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "ObjectiveC",
  "identifier" : "/documentation/ObjectiveC/NSObject-swift.class/initialize()",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Objective-C Runtime"
    ],
    "preciseIdentifier" : "c:objc(cs)NSObject(cm)initialize"
  },
  "title" : "initialize()"
}
-->

# initialize()

Initializes the class before it receives its first message.

```
class func initialize()
```

## Discussion

The runtime sends [`initialize()`](/documentation/ObjectiveC/NSObject-swift.class/initialize()) to each class in a program just before the class, or any class that inherits from it, is sent its first message from within the program. Superclasses receive this message before their subclasses.

The runtime sends the [`initialize()`](/documentation/ObjectiveC/NSObject-swift.class/initialize()) message to classes in a thread-safe manner. That is, [`initialize()`](/documentation/ObjectiveC/NSObject-swift.class/initialize()) is run by the first thread to send a message to a class, and any other thread that tries to send a message to that class will block until [`initialize()`](/documentation/ObjectiveC/NSObject-swift.class/initialize()) completes.

The superclass implementation may be called multiple times if subclasses do not implement [`initialize()`](/documentation/ObjectiveC/NSObject-swift.class/initialize())—the runtime will call the inherited implementation—or if subclasses explicitly call `[super initialize]`. If you want to protect yourself from being run multiple times, you can structure your implementation along these lines:

```objc
+ (void)initialize {
  if (self == [ClassName self]) {
    // ... do the initialization ...
  }
}
```

Because [`initialize()`](/documentation/ObjectiveC/NSObject-swift.class/initialize()) is called in a blocking manner, it’s important to limit method implementations to the minimum amount of work necessary possible. Specifically, any code that takes locks that might be required by other classes in their [`initialize()`](/documentation/ObjectiveC/NSObject-swift.class/initialize()) methods is liable to lead to deadlocks. Therefore, you should not rely on [`initialize()`](/documentation/ObjectiveC/NSObject-swift.class/initialize()) for complex initialization, and should instead limit it to straightforward, class local initialization.

### Special Considerations

[`initialize()`](/documentation/ObjectiveC/NSObject-swift.class/initialize()) is invoked only once per class. If you want to perform independent initialization for the class and for categories of the class, you should implement [`load()`](/documentation/ObjectiveC/NSObject-swift.class/load()) methods.

## See Also

[`class`](/documentation/ObjectiveC/NSObject-c.protocol/class)

Returns the class object for the receiver’s class.

[`init()`](/documentation/ObjectiveC/NSObject-swift.class/init())

Implemented by subclasses to initialize a new object (the receiver) immediately after memory for it has been allocated.



---

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)