[ad_1]
I’ve created a mannequin and I must attempt to add worth to one of many CodingKey‘s case
struct Mannequin {
let descriptions: String
}
enum CodingKeys: String, CodingKey {
case descriptions = "INFO-(NSLocalizedString("Language", remark: ""))"
}
init(from decoder: Decoder) throws {
let container = attempt decoder.container(keyedBy: CodingKeys.self)
descriptions = attempt container.decode(String.self, forKey: .descriptions)
}
Now compiler provides me this error
🛑 Uncooked worth for enum case have to be a literal
How can I repair this error?
Edited:
Decoding:
remaining class ModelData: ObservableObject {
@Printed var dinosaurs: [String:Model] = load("information.plist")
}
func load<T: Decodable>(_ filename: String) -> T {
let information: Knowledge
guard let file = Bundle.essential.url(forResource: filename, withExtension: nil)
else {
fatalError("Could not discover (filename) in essential bundle.")
}
do {
information = attempt Knowledge(contentsOf: file)
} catch {
fatalError("Could not load (filename) from essential bundle:n(error)")
}
do {
let decoder = PropertyListDecoder()
return attempt decoder.decode(T.self, from: information)
} catch {
fatalError("Could not parse (filename) as (T.self):n(error)")
}
}
[ad_2]
