Skip to content

Latest commit

History

30 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

IDKit

Simple and lightweight library that provides a set of classes and functions to work with identifiers.

AnyID

No longer need to use String or Int for your identifiers. Just use AnyID and forget about type casting.

structUser:Codable{letid:AnyIDletname:Stringletage:Int}

TypedID

TypedID<...> represents an identifier as a strong type identifier. TID<...> - abbreviation for easy using

IDRepresentable

Protocol can be used to define your custom identifier types.

structUser:IDRepresentable{
// let id: AnyID <-- property is not required
letname:Stringletage:Int}
// but in any place you can identify your strong type id
letidentifier:TID<User>

IDContract

It's like combine of TypedID/TID and IDRepresentable protocols. It's required to have a property with name id of type TypedID<Self>. The library automatically confirms the Swift.Identifiable protocol with the id property of the TypedID<Self> type.

structUser:IDContract{letid:TypedID<Self><-- property is required}

Known issue: SwiftUI+Preview crash

Based on bug in SwiftUI+Preview that is crashing when using ForEach with IDContract models which conforms Identifiable by default It's a bug in SwiftUI+Preview, not in this package. Some times it works, but sometimes it crashes...

  • ⚠️ If you don't use SwiftUI+Preview, then you definitely won't need this code!
  • This is a workaround to fix the crash and show SwiftUI+Preview. You can use Simulator without that workaround to avoid this crash.
  • Xcode 15.4 is still crashing, waiting for a fix in Xcode 16.0... or in future versions from Apple 🤷‍♂️

Usage

ForEach(.fixID($items)){ item in
// take the properties from the item directly
letsome= item.some
// or
// take the original item
letitem= item.original
}

Crash log

== PREVIEW UPDATE ERROR:
LinkDylibError: Failed to build RoutesView.swift
Linking failed: linker command failed with exit code 1 (use -v to see invocation)
ld: warning: search path '/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator' not found
ld: warning: Could not find or use auto-linked framework 'CoreAudioTypes': framework 'CoreAudioTypes' not found
Undefined symbols for architecture arm64:
"nominal type descriptor for IDKit.TypedID", referenced from:

About

Simple and lightweight library that provides a set of classes and functions to work with identifiers

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages