<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSTextAttachmentLayout/viewProvider(for:location:textContainer:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "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: UIView?, location: any NSTextLocation, textContainer: NSTextContainer?) -> NSTextAttachmentViewProvider?
```

## Parameters

`parentView`

The parent view.

`location`

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

`textContainer`

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

## Return Value

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

## Discussion

The default implementation queries the text attachment view provider class using the [`textAttachmentViewProviderClass(forFileType:)`](/documentation/UIKit/NSTextAttachment/textAttachmentViewProviderClass(forFileType:)) method of [`NSTextAttachment`](/documentation/UIKit/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)