<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSTextViewportRenderingSurfaceKey",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextViewportRenderingSurfaceKey"
  },
  "title" : "NSTextViewportRenderingSurfaceKey"
}
-->

# NSTextViewportRenderingSurfaceKey

A protocol that lets you use an object to identify a rendering surface when storing or retrieving it.

```
protocol NSTextViewportRenderingSurfaceKey : NSObjectProtocol
```

## Overview

When TextKit lays out text in a viewport, it can ask your delegate to store and retrieve rendering surfaces across layout passes. Objects that conform to `NSTextViewportRenderingSurfaceKey` act as the identifier for each surface — TextKit passes them to your delegate when it needs to store or look one up.

Two types conform to this protocol by default:

- **`NSTextLayoutFragment`** — Use a layout fragment as a key to cache a rendering surface per fragment. This is the most common approach.
- **`NSString`** — Use a string as a key when you want to associate a rendering surface with a name rather than a fragment.

## Relationships

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

### Conforming Types

[`NSTextLayoutFragment`](/documentation/UIKit/NSTextLayoutFragment)

---

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)