fix(swift): add ignored LocaleMap type

This commit is contained in:
Lukas Obermann
2024-11-17 16:07:31 +01:00
parent 6dd361a16c
commit f80bbaa828
2 changed files with 27 additions and 0 deletions
@@ -0,0 +1,27 @@
//
// _LocaleMap.swift
// Database
//
// Created by Lukas Obermann on 11.11.24.
//
import Foundation
public struct LocaleMap<T: EntitySubtype>: EntitySubtype {
private var map: [Foundation.Locale: T]
public init(_ map: [Foundation.Locale: T]) {
self.map = map
}
public init(from decoder: any Decoder) throws {
let dict = try decoder.singleValueContainer().decode([String: T].self)
self.map = Dictionary(uniqueKeysWithValues: dict.map { (localeId, value) in
(key: Foundation.Locale(identifier: localeId), value: value)
})
}
public subscript (_ locale: Foundation.Locale) -> T? {
return map[locale]
}
}