Latest 1.1.1
License MIT
Platforms ios 8.0, tvos 9.0

As You Type Formatter

CI Status
Carthage Compatible

As You Type Formatter. By assuming text is always in a state of correctness, this library aims to make the minimal amount of state changes; only overriding the text change process when multiple text attributes are needed or existing text needs to be changed.

  • Performant – O(newText.count + nextWord.count) worst case.
  • Customization – Provide own character prefixes and formats.
  • Suggestions – Detects when customized words has been selected, and methods to replace these words.
  • Delegate – Methods to detect when different text formats are in use, and new suggestions are required.


  • iOS 8.0+ / tvOS 9.0+
  • Xcode 10.3+
  • Swift 4.2+



CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate AsYouTypeFormatter into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'AsYouTypeFormatter'


Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate AsYouTypeFormatter into your Xcode project using Carthage, specify it in your Cartfile:

github "philip-bui/as-you-type-formatter"

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but AsYouTypeFormatter does support its use on supported platforms.

Once you have your Swift package set up, adding AsYouTypeFormatter as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "", from: "1.1.0"))


  • Character Prefix. Default # @, words beginning with character prefixes use their assigned text attributes.

  • Delimiters. Default emojis and non-alphanumeric characters, delimiters indicate when a word has ended to use normal text attributes.

AsYouTypeFormatter overrides two UITextView methods, textView(shouldChangeTextIn:text:) and textViewDidChangeSelection(). You can delegate your UITextView or call the methods within your own delegate.

import AsYouTypeFormatter

// AppDelegate.swift - Modify global defaults.
AsYouTypeFormatter.normalAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)]
AsYouTypeFormatter.tagAttributes = [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 16)]
AsYouTypeFormatter.mentionAttributes = [NSAttributedString.Key.font: UIFont.italicSystemFont(ofSize: 16)]

// ViewController.swift - Customize own character prefixes and formats.
private lazy var typeFormatter: AsYouTypeFormatter = {
    // Implicit return.
    AsYouTypeFormatter(delegate: self, attributes: [
    "#": [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 16)],
    nil: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)]

Design Decisions

  • Default Delimiters. The default delimiters are Emojis, and characters not in Unicode Category L* or 0-9. Delegate methods can customize this.
  • No suggestion support for UITextField. Suggestion support replies on detecting when the user selects a new word, and UITextFieldDelegate doesn’t expose text selection events.
  • Link supports. Enabling selectable and clickable text is not very practical.
  • On multi-text selection, suggestions are disabled. The assumption is that text is usually selected when the user wants to copy and paste.


AsYouTypeFormatter is available under the MIT license. See LICENSE for details.

Latest podspec

    "name": "AsYouTypeFormatter",
    "version": "1.1.1",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "summary": "As You Type Formatter.",
    "description": "Format text as you type, given certain character prefixes such as hashtags and mentions.",
    "homepage": "",
    "authors": {
        "Philip Bui": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.1.1"
    "documentation_url": "",
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0"
    "source_files": "Sources/**/*.swift",
    "swift_version": "4.2"

Pin It on Pinterest

Share This