---
title: "init(data:ofType:)"
framework: uikit
role: symbol
role_heading: Initializer
path: "uikit/nstextattachment/init(data:oftype:)"
---

# init(data:ofType:)

Creates a text attachment object with the specified data.

## Declaration

```swift
init(data contentData: Data?, ofType uti: String?)
```

## Parameters

- `contentData`: Data to use for the text attachment contents. Can be nil.
- `uti`: A uniform type identifier specifying the data type of the attachment contents. Can be nil.

## Return Value

Return Value A new NSTextAttachment object.

## Discussion

Discussion This method is the designated initializer for the NSTextAttachment class on iOS. When either contentData or uti is nil, TextKit considers the receiver to be an attachment without document contents. In this case, the NSAttributedString external file writing methods try to save the value of the image property instead.

## See Also

### Initializing a text attachment

- [init(fileWrapper:)](appkit/nstextattachment/init(filewrapper:).md)
- [init(image:)](uikit/nstextattachment/init(image:).md)
