В настоящее время у меня есть решение, в котором я обертываю UIFont в структуру Font, подобную этой
Код: Выделить всё
public struct Font: Decodable{
let font: UIFont
private enum CodingKeys: String, CodingKey {
case size
case font
}
public init(from decoder: Decoder){
do{
let values = try decoder.container(keyedBy: CodingKeys.self)
font = UIFont(name: try values.decode(String.self, forKey: .font), size: try values.decode(CGFloat.self, forKey: .size))!
} catch{
fatalError("Font configuration error:\(error)")
}
}
}
Код: Выделить всё
final class Font: UIFont, Decodable{
private enum CodingKeys: String, CodingKey {
case size
case font
}
convenience init(from decoder: Decoder) {
do{
let values = try decoder.container(keyedBy: CodingKeys.self)
super.init(name: try values.decode(String.self, forKey: .font), size: try values.decode(CGFloat.self, forKey: .size))
} catch{
fatalError("Font configuration error:\(error)")
}
}
}
Любые предложения о том, как привести UIFont в соответствие с Декодируемость без упаковки приветствуется.
Подробнее здесь: https://stackoverflow.com/questions/563 ... -decodable
Мобильная версия