---
title: "replaceSelection(_:withCharacters:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/attributedstring/replaceselection(_:withcharacters:)"
---

# replaceSelection(_:withCharacters:)

Replace the selection with new content, attributed with the typing attributes.

## Declaration

```swift
mutating func replaceSelection(_ selection: inout AttributedTextSelection, withCharacters newContent: some Collection<Character>)
```

## Discussion

Discussion Operates just like replaceSelection(_:with:), but applies the typing attributes to the new content before inserting it.
