<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAttributedString/init(attachment:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAttributedString(cm)attributedStringWithAttachment:"
  },
  "title" : "init(attachment:)"
}
-->

# init(attachment:)

Creates an attributed string with an attachment.

```
init(attachment: NSTextAttachment)
```

## Parameters

`attachment`

The attrachment to place in the string.

## Return Value

An attributed string containing the attachment.

## Discussion

This is a convenience method for creating an attributed string containing an attachment using <doc://com.apple.documentation/documentation/AppKit/NSTextAttachment/character> as the base character.

---

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)