TagKit is a library that makes it easy to use tags and slugify strings in Swift and SwiftUI.
You can slug and tag any type, customize the slug format, and use the built-in views to list and edit tags with ease.
TagKit can be installed with the Swift Package Manager:
https://github.com/danielsaidi/TagKit.git
You can become a sponsor to help me dedicate more time on my various open-source tools. Every contribution, no matter the size, makes a real difference in keeping these tools free and actively developed.
TagKit lets you slugify strings and manage tags for any taggable type.
Slugifying a string means to remove unwanted characters and replacing whitespaces with a separator. This is often used in urls, where a page slug creates a unique, valid url that also describes the content.
TagKit has a Swift/String/slugified(with:) string extension that lets you slugify strings with a standard or custom SlugConfiguration:
let custom = SlugConfiguration(
separator: "+",
allowedCharacters: .init(charactersIn: "hewo")
)
"Hello, world!".slugified() // "hello-world"
"Hello, world!".slugified(with: custom) // "he+wo"
Slugified strings are automatically lowercased, since a slug should be case-insensitively unique.
Tagging is the process of adding tags to an item, with the intent to categorize, group, filter and search among tags.
TagKit has a Taggable protocol that can be implemented by any type that has mutable Taggable/tags:
public protocol Taggable {
var tags: [String] { get set }
}Once a type implements Taggable, it can make use of a lot of automatically implemented functionality that the protocol provides, like Taggable/hasTags, Taggable/slugifiedTags, Taggable/addTag(_:), Taggable/removeTag(_:), Taggable/toggleTag(_:). All Taggable collections are extended as well.
TagKit has a couple of tag related views, like TagList, TagEditList and TagTextField.
The online documentation has more information, articles, code examples, etc.
Feel free to reach out if you have questions or if you want to contribute in any way:
- Website: danielsaidi.com
- E-mail: daniel.saidi@gmail.com
- Bluesky: @danielsaidi@bsky.social
- Mastodon: @danielsaidi@mastodon.social
TagKit is available under the MIT license. See the LICENSE file for more info.
