---
title: "init(string:attributes:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsattributedstring/init(string:attributes:)"
---

# init(string:attributes:)

Creates an attributed string with the specified text and attributes.

## Declaration

```swift
init(string str: String, attributes attrs: [NSAttributedString.Key : Any]? = nil)
```

## Parameters

- `str`: The text for the new attributed string.
- `attrs`: The attributes for the new attributed string. This method applies the attributes to the entire string. For a list of attributes that you can include in this dictionary, see doc://com.apple.foundation/documentation/Foundation/NSAttributedString/Key.

## Discussion

Discussion Returns an NSAttributedString object initialized with the characters of str and the attributes of attrs.

## See Also

### Related Documentation

- [init(RTF:documentAttributes:)](foundation/nsattributedstring/init(rtf:documentattributes:).md)

### Creating from another string

- [init(string:)](foundation/nsattributedstring/init(string:).md)
- [init(attributedString:)](foundation/nsattributedstring/init(attributedstring:).md)
