Swiftpack.co - danielsaidi/RichTextKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by danielsaidi.
danielsaidi/RichTextKit 0.9.9
RichTextKit is a Swift-based library for working with rich text in UIKit, AppKit and SwiftUI.
⭐️ 654
🕓 5 days ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/danielsaidi/RichTextKit.git", from: "0.9.9")

RichTextKit Logo

Version Swift 5.8 MIT License Twitter: @danielsaidi Mastodon: @danielsaidi@mastodon.social

About RichTextKit

RichTextKit helps you view and edit rich text in SwiftUI, UIKit and AppKit.

RichTextKit has a multi-platform SwiftUI RichTextEditor that can be added to any app:

The RichTextEditor supports text styles (bold, italic, underline, etc.), fonts and font sizes, colors, text alignments, image attachments, etc.

The RichTextEditor is powered by a UIKit/AppKit RichTextView that bridges the UIKit UITextView and AppKit NSTextView and adds APIs to make the view work similar on both platforms.


RichTextKit can be installed with the Swift Package Manager:


If you prefer to not have external dependencies, you can also just copy the source code into your app.

Getting started

RichTextKit has a SwiftUI RichTextEditor that takes a text binding and a RichTextContext:

struct MyView: View {

    private var text = NSAttributedString(string: "Type here...")
    var context = RichTextContext()

    var body: some View {
        RichTextEditor(text: $text, context: context) {
            // You can customize the native text view here

The editor uses a RichTextCoordinator to sync changes between the editor, context, and platform-specific view. You can use the context to change font, colors, alignment etc. and observe context changes to update the UI.

For more information, please see the getting started guide.


The online documentation has more information, articles, code examples, etc.

Demo Application

The demo app lets you explore the library on iOS and macOS. To try it out, just open and run the Demo project.

Support my work

You can sponsor me on GitHub Sponsors or reach out for paid support, to help support my open-source projects.


Feel free to reach out if you have questions or want to contribute in any way:


RichTextKit is available under the MIT license. See the LICENSE file for more info.


Stars: 654
Last commit: 17 hours ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups


Release Notes

5 days ago

This release adds a lot of new RichTextAction cases and adjusts the context and coordinator subscription.

This release also deprecates RichTextAttributeReader and RichTextAttributeWriter functionality that are not used by the library, in favor of RichTextViewComponent, to reduce the complexity of the library.

Until now, these functions mostly did the same thing, but sometimes the RichTextViewComponent have to use its text storage or layout manager, or update the typing attributes. This caused the code to diverge and mostly identical copies had co-exist, where the reader and writer versions were not even used by the library.

By deprecating these functions, we can simplify the library in 1.0, and focus more on unifying the different RichTextViewComponent implementations (UITextView in iOS and NSTextView in macOS), rather than providing a low level string handling interface.

✨ Features

  • FontRepresentable has new extensions.
  • RichTextAction has a new label property.
  • RichTextCommand.ActionButtonGroup has new inits.
  • RichTextCommand.FormatMenu is a lot more configurable.
  • RichTextFormatSheet is now available on all platforms.
  • RichTextFormatSheet has new configuration and style types.
  • RichTextFormatSidebar has new configuration and style types.
  • RichTextFormatToolbar is a new rich text formatting toolbar.
  • RichTextKeyboardToolbar has a new config to always be shown.
  • RichTextLine is a new namespace with support for linespacing.
  • RichTextStyle.Button now supports using custom button styles.
  • RichTextView has a new theme that lets you define its style.
  • RichTextViewComponent has a new hasRichTextStyle function.
  • RichTextViewComponent has a new toggleRichTextStyle function.
  • RichTextViewComponent now handles superscript changes properly.

🚨 Important

  • RichTextFormatToolbar is no longer navigation wrapped by default.
  • RichTextFormatToolbar has a new asSheet() function that does this.

💡 Adjustments

  • RichTextColor icon is no longer optional.
  • RichTextColor has a new titleKey property.
  • RichTextContext makes coordinator handle alignment.
  • RichTextCoordinator now syncs an extra time at ends editing.

🐛 Bug Fixes

  • The library once again builds on visionOS.
  • RichTextAlignment now behaves better.
  • RichTextAlignment.Picker now uses provided values.
  • RichTextCoordinator now handles indentation changes.

🗑️ Deprecations

  • RichTextAttributeReader has deprecated a lot of functions.
  • RichTextAttributeWriter has deprecated a lot of functions.
  • RichTextCommand.AlignmentOptionsGroup has been deprecated.
  • RichTextCommand.FontSizeOptionsGroup has been deprecated.
  • RichTextCommand.IndentOptionsGroup has been deprecated.
  • RichTextCommand.StyleOptionsGroup has been deprecated.
  • RichTextCommand.SuperscriptOptionsGroup has been deprecated.
  • RichTextContext replaces individual colors with a single colors.
  • RichTextContext replaces individual styles with a single styles.
  • RichTextContext userActionPublisher is renamed to actionPublisher.
  • RichTextCoordinator functions calling handle(_:) have been deprecated.
  • RichTextFormatSheet has been renamed to RichTextFormatToolbar.
  • RTKL10n.bundle has been deprecated since we can use the .module bundle.

💥 Breaking Changes

  • RichTextColor.undefined was no longer used and has been removed.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics