---
title: "insert(_:at:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsmutableattributedstring/insert(_:at:)"
---

# insert(_:at:)

Inserts the characters and attributes of the given attributed string into the receiver at the given index.

## Declaration

```swift
func insert(_ attrString: NSAttributedString, at loc: Int)
```

## Parameters

- `attrString`: The string whose characters and attributes are inserted.
- `loc`: The index at which the characters and attributes are inserted.

## Discussion

Discussion The new characters and attributes begin at the given index and the existing characters and attributes from the index to the end of the receiver are shifted by the length of the attributed string. Raises an rangeException if loc lies beyond the end of the receiver’s characters.

## See Also

### Changing Characters and Attributes

- [append(_:)](foundation/nsmutableattributedstring/append(_:).md)
- [replaceCharacters(in:with:)](foundation/nsmutableattributedstring/replacecharacters(in:with:)-1uaw7.md)
- [setAttributedString(_:)](foundation/nsmutableattributedstring/setattributedstring(_:).md)
