Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension Extension {
struct Filters {
enum Error: Swift.Error {
case invalidInputType
case invalidOption(option: String)
}
static func swiftProperty(_ value: Any?) throws -> Any? {
let string = try Filters.parseString(from: value)
return string.swiftProperty
}
static func parseString(from value: Any?) throws -> String {
if let losslessString = value as? LosslessStringConvertible {
return String(describing: losslessString)
}
if let string = value as? String {
return string
}
throw Error.invalidInputType
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment