Skip to content

Using Tagged with TCA Shared #78

Answered by bradhowes
bradhowes asked this question in Q&A
Discussion options

You must be logged in to vote

After some playing around, I was able to build a wrapper that seems to do the job:

public struct Foo {}
public typealias FooKey = Tagged<Foo, UUID>

public struct CustomAppStorageKey<Value: Sendable, Stored: Sendable> : Sendable {
  private let wrapped: AppStorageKey<Stored>
  private let encoder: @Sendable (Value) -> Stored
  private let decoder: @Sendable (Stored) -> Value

  public init(
    _ wrapped: AppStorageKey<Stored>,
    encoder: @escaping @Sendable (Value)-> Stored,
    decoder: @escaping @Sendable (Stored) -> Value
  ) {
    self.wrapped = wrapped
    self.encoder = encoder
    self.decoder = decoder
  }
}

extension PersistenceReaderKey where Self == CustomAppStorageKey<FooK…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@bradhowes
Comment options

Answer selected by bradhowes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant