Welcome to Tagging, a small library that makes it easy to create type-safe tags in Swift. Categorization are often very useful for our models, so leveraging the compiler to ensure that they're used in a correct manner can go a long way to making the model layer of an app or system more robust.
This library is strongly inspired by JohnSundell/🆔entity and mbleigh/acts-as-taggable-on, for theoretical information, check out "Type-safe identifiers in Swift" on Swift by Sundell.
All you have to do to use Tagging is to make a model conform to Taggable
, and give it an tags
property, like this:
struct Article: Taggable {
let tags: [Tag<Article>]
let title: String
}
And just like that, the above Article
tags are now type-safe! Thanks to Swift’s type inference capabilities, it’s also possible to implement an Taggable
type’s tags
simply by using Tags
as its type:
struct Article: Taggable {
let tags: Tags<