<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLProtocol/registerClass(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLProtocol(cm)registerClass:"
  },
  "title" : "registerClass(_:)"
}
-->

# registerClass(_:)

Attempts to register a subclass of [`URLProtocol`](/documentation/Foundation/URLProtocol), making it visible to the URL loading system.

```
class func registerClass(_ protocolClass: AnyClass) -> Bool
```

## Parameters

`protocolClass`

The subclass to register.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the registration is successful, <doc://com.apple.documentation/documentation/Swift/false> otherwise. The only failure condition is if `protocolClass` is not a subclass of [`URLProtocol`](/documentation/Foundation/URLProtocol).

## Discussion

Register any custom [`URLProtocol`](/documentation/Foundation/URLProtocol) subclasses prior to making URL requests. When the URL loading system begins to load a request, it tries to initialize each registered protocol class with the specified request. The first [`URLProtocol`](/documentation/Foundation/URLProtocol) subclass to return <doc://com.apple.documentation/documentation/Swift/true> when sent a [`canInit(with:)`](/documentation/Foundation/URLProtocol/canInit(with:)-76brg) message is used to load the request. There is no guarantee that all registered protocol classes will be consulted.

Classes are consulted in the reverse order of their registration. A similar design governs the process to create the canonical form of a request with [`canonicalRequest(for:)`](/documentation/Foundation/URLProtocol/canonicalRequest(for:)).

---

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)