---
title: "registerClass(_:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/urlprotocol/registerclass(_:)"
---

# registerClass(_:)

Attempts to register a subclass of URLProtocol, making it visible to the URL loading system.

## Declaration

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

## Parameters

- `protocolClass`: The subclass to register.

## Return Value

Return Value true if the registration is successful, false otherwise. The only failure condition is if protocolClass is not a subclass of URLProtocol.

## Discussion

Discussion Register any custom 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 subclass to return true when sent a canInit(with:) 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:).

## See Also

### Registering and unregistering protocol classes

- [unregisterClass(_:)](foundation/urlprotocol/unregisterclass(_:).md)
