MasterJ93 / ATProtoKit

A straightforward solution for using AT Protocol and Bluesky, written in Swift.

Home Page:https://atprotokit.cjrriley.com/documentation/atprotokit/

Repository from Github https://github.comMasterJ93/ATProtoKitRepository from Github https://github.comMasterJ93/ATProtoKit

[Feature Request]: Handle `Locale` in `Decodable`

MasterJ93 opened this issue · comments

Summary

KeyedDecodingContainer will need to be extended to support Locale.

Pain points

As it stands, Locale has trouble being decoded. If doing so directly, then a decoding error is thrown.

As a solution, we need methods that will handle the translation for us.

The solution is to extend KeyedDecodingContainer with the following:

  • encodeLocale()
  • encodeLocaleIfPresent()

This will function similarly with truncatedEncode[IfPresent]().

Considered Alternatives

We could write the code like this in a custom decoding method:

let string = try container.decode(String.self, forKey: .lang)
self.lang = Locale(identifier: str)

However, this looks ugly. A one-lined solution is better.

Is this a breaking change?

No

Library Examples

No response

Additional Context

No response

This has been completed. Closing issue.