> ## Content Index
> Fetch the complete content index at: https://williamboles.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Building Delegates Like They Do in UIKit
- URL: https://williamboles.com/implementing-nsobject-protocol-in-your-protocols/
- Published: 2011-12-07T21:09:00.000Z
- Updated: 2026-09-26T09:09:22.000Z
- Description: We've all written delegates, but sometimes our delegates require more information than what we receive from UIKit. Why is this? Here, we look at how conforming our protocol to NSObject brings us closer to UIKit delegates.
- Author: William Boles
- Tags: Protocols, UIKit

In [UIKit](https://developer.apple.com/documentation/uikit?ref=williamboles.com), I often see delegate properties being declared as `id` and those delegates being able to access the `performSelector` method. In contrast, when I write custom protocols to be used as delegates, those delegates need to be of type `NSObject` to access `performSelector`.

Take this example protocol:

```
@protocol CustomDelegate

- (void)doAwesomeness;

@end
```

To access `performSelector`, I would need to declare the delegate as:

```
NSObject<CustomDelegate> *delegate;
```

Rather than the more common:

```
id<CustomDelegate> delegate;
```

Is there some magic that Apple are sprinkling on their protocols that allows them access to greater functionality that I'm not?

Well, yes and that magic isn't even hidden, just easy to miss - it's the [NSObject protocol](https://developer.apple.com/documentation/objectivec/nsobjectprotocol?ref=williamboles.com).

> Confusingly, `NSObject` is both a protocol and a concrete type - the concrete type `NSObject` conforms to the protocol `NSObject`. Here we are talking about the protocol, not the concrete type.

Let's use [UITextDelegate](https://developer.apple.com/documentation/uikit/uitextfielddelegate?ref=williamboles.com) as our `UIKit` example and examine it more closely. The first thing you will notice is that, unlike `CustomDelegate`, `UITextDelegate` inherits from the protocol `NSObject`:

```
@protocol UITextFieldDelegate <NSObject>
```

Any type that wants to conform to `UITextFieldDelegate` must also conform to `NSObject`. `NSObject` is where `performSelector` is declared. So it is safe to call `performSelector` on that property as the compiler knows that `UITextFieldDelegate` is a specialised form of `NSObject`.

`CustomDelegate` doesn't enforce that a type that conforms to it must also conform to `NSObject`. The compiler cannot guarantee that any conforming type will implement `performSelector`, so it prevents potentially unsafe calls to `performSelector` on that property.

Updating `CustomDelegate` to inherit the `NSObject` protocol means that I can use `id` as the property type, allowing my protocols to feel more like those we get from `UIKit`.