<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextAttachmentLayout/viewProvider(for:location:textContainer:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextAttachmentLayout(im)viewProviderForParentView:location:textContainer:"
  },
  "title" : "viewProvider(for:location:textContainer:)"
}
-->

# viewProvider(for:location:textContainer:)

Returns the text attachment view provider corresponding to the file type.

```
func viewProvider(for parentView: NSView?, location: any NSTextLocation, textContainer: NSTextContainer?) -> NSTextAttachmentViewProvider?
```

## Parameters

`parentView`

The parent view.

`location`

An <[`NSTextLocation`](/documentation/AppKit/NSTextLocation) that indicates that start of the string.

`textContainer`

The[`NSTextContainer`](/documentation/AppKit/NSTextContainer) that contains the source text.

## Return Value

An [`NSTextAttachmentViewProvider`](/documentation/AppKit/NSTextAttachmentViewProvider).

## Discussion

The default implementation queries the text attachment view provider class using the [`textAttachmentViewProviderClass(forFileType:)`](/documentation/AppKit/NSTextAttachment/textAttachmentViewProviderClass(forFileType:)) method of [`NSTextAttachment`](/documentation/AppKit/NSTextAttachment). When non-`nil`, it instantiates a view, then, fills properties declared in `NSTextAttachmentViewProvider` if implemented.

---

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)