Swiftpack.co -  lucamegh/Identifier as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Type-safe identifiers.
.package(url: "https://github.com/lucamegh/Identifier.git", from: "1.0.0")

Identifier 🧬

Type-safe identifiers.


Identifier is distributed using Swift Package Manager. To install it into a project, simply add it as a dependency within your Package.swift manifest:

let package = Package(
    dependencies: [
        .package(url: "https://github.com/lucamegh/Identifier", from: "1.0.0")


Let's have a look at this User type:

struct User {

    let id: String

    let fullName: String

While this implementation is fine, we could do even better by refactoring the id using Identifier.

struct User {

    let id: Identifier<Self, String>

    let fullName: String

To clean things up, let's introduce a new typealias:

extension User {

    typealias ID = Identifier<Self, String>

struct User {

    let id: ID

    let fullName: String

Much better!

When using Identifier, it's no longer possible to pass the wrong identifier around:

func addToFavorites(id: Recipe.ID) { ... }

func addToFavorites(id: user.id) // This code won't compile!


This library was inspired by John Sundell's Type-safe identifiers in Swift article.


Stars: 0
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Identifier 1.0.0
2 weeks ago

The first release of Identifier.

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