<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/AnyClass",
  "metadataVersion" : "0.1.0",
  "role" : "Type Alias",
  "symbol" : {
    "kind" : "Type Alias",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s8AnyClassa"
  },
  "title" : "AnyClass"
}
-->

# AnyClass

The protocol to which all class types implicitly conform.

```
typealias AnyClass = any AnyObject.Type
```

## Discussion

You can use the `AnyClass` protocol as the concrete type for an instance of
any class. When you do, all known `@objc` class methods and properties are
available as implicitly unwrapped optional methods and properties,
respectively. For example:

```
class IntegerRef {
    @objc class func getDefaultValue() -> Int {
        return 42
    }
}

func getDefaultValue(_ c: AnyClass) -> Int? {
    return c.getDefaultValue?()
}
```

The `getDefaultValue(_:)` function uses optional chaining to safely call
the implicitly unwrapped class method on `c`. Calling the function with
different class types shows how the `getDefaultValue()` class method is
only conditionally available.

```
print(getDefaultValue(IntegerRef.self))
// Prints "Optional(42)"

print(getDefaultValue(NSString.self))
// Prints "nil"
```

---

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)