---
title: "smartInsert(afterStringFor:replacing:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstextview/smartinsert(afterstringfor:replacing:)"
---

# smartInsert(afterStringFor:replacing:)

Returns any whitespace that needs to be added after the string to preserve proper spacing and punctuation when the string replaces the characters in the specified range.

## Declaration

```swift
func smartInsert(afterStringFor pasteString: String, replacing charRangeToReplace: NSRange) -> String?
```

## Parameters

- `pasteString`: The string that is replacing the characters in charRange.
- `charRangeToReplace`: The range of characters which aString is replacing.

## Return Value

Return Value Any whitespace that needs to be added after aString to preserve proper spacing and punctuation when the characters in charRange are replaced by  aString. If aString is nil or if smart insertion and deletion are disabled, this method returns nil.

## Discussion

Discussion Don’t invoke this method directly. Instead, use smartInsert(for:replacing:before:after:), which calls this method as part of its implementation.

## See Also

### Customizing subclass behaviors

- [updateFontPanel()](appkit/nstextview/updatefontpanel().md)
- [updateRuler()](appkit/nstextview/updateruler().md)
- [acceptableDragTypes](appkit/nstextview/acceptabledragtypes.md)
- [updateDragTypeRegistration()](appkit/nstextview/updatedragtyperegistration().md)
- [selectionRange(forProposedRange:granularity:)](appkit/nstextview/selectionrange(forproposedrange:granularity:).md)
- [rangeForUserCharacterAttributeChange](appkit/nstextview/rangeforusercharacterattributechange.md)
- [rangesForUserCharacterAttributeChange](appkit/nstextview/rangesforusercharacterattributechange.md)
- [rangeForUserParagraphAttributeChange](appkit/nstextview/rangeforuserparagraphattributechange.md)
- [rangesForUserParagraphAttributeChange](appkit/nstextview/rangesforuserparagraphattributechange.md)
- [rangeForUserTextChange](appkit/nstextview/rangeforusertextchange.md)
- [rangesForUserTextChange](appkit/nstextview/rangesforusertextchange.md)
- [shouldChangeText(in:replacementString:)](appkit/nstextview/shouldchangetext(in:replacementstring:).md)
- [shouldChangeText(inRanges:replacementStrings:)](appkit/nstextview/shouldchangetext(inranges:replacementstrings:).md)
- [didChangeText()](appkit/nstextview/didchangetext().md)
- [smartInsertDeleteEnabled](appkit/nstextview/smartinsertdeleteenabled.md)
