How to make LocalizedStingKey type conform to Codable protocol in Swift?

257 Views Asked by At

How to make LocalizedStingKey type conform to Codable protocol in Swift? A simple Person struct. If do not remove country property, compiler not work.

struct Person: Codable {
    let name: String
    let age: Int
    let description: LocalizedKeyString // more words in description property
}
1

There are 1 best solutions below

0
Edwardai On

I decided to use String type and not add computed property because properties in my custom type is a little more.

If use computed property, the following code work:

struct Person: Codable {
let name: String
let age: Int
let description: String

var localizedDescription: LocalizedStringKey {
    return LocalizedStringKey(description)
}

}