33 lines
825 B
Swift
33 lines
825 B
Swift
extension KeyedDecodingContainer {
|
|
public func decodeFloatOrString(forKey key: Key) throws -> Float? {
|
|
if let floatVal = try? decode(Float.self, forKey: key) {
|
|
return floatVal
|
|
}
|
|
if let stringVal = try? decode(String.self, forKey: key) {
|
|
return Float(stringVal)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
public func decodeIntOrString(forKey key: Key) throws -> Int? {
|
|
if let intVal = try? decode(Int.self, forKey: key) {
|
|
return intVal
|
|
}
|
|
if let stringVal = try? decode(String.self, forKey: key) {
|
|
return Int(stringVal)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
public func decodeStringOrArray(forKey key: Key) throws -> String? {
|
|
if let arrayVal = try? decode([String].self, forKey: key) {
|
|
return arrayVal.joined(separator: ",")
|
|
}
|
|
if let stringVal = try? decode(String.self, forKey: key) {
|
|
return stringVal
|
|
}
|
|
return nil
|
|
}
|
|
|
|
}
|