Skip to content

Instantly share code, notes, and snippets.

@jonbrooks
Last active September 17, 2018 21:33
Show Gist options
  • Save jonbrooks/a2f0f19d8bcb00b51cf1b0567d06c720 to your computer and use it in GitHub Desktop.
Save jonbrooks/a2f0f19d8bcb00b51cf1b0567d06c720 to your computer and use it in GitHub Desktop.
InfiniteRecursion
struct Foo {
let json: [Any]
}
extension Foo: Decodable {
enum Keys: String, CodingKey {
case json
}
init(from decoder: Decoder) throws {
let cont = try decoder.container(keyedBy: Keys.self)
json = try cont.decode(Array<Any>.self, forKey: .json)
}
}
let json = """
{
"json": [[ "a", "b", "C" ]]
}
""".data(using: .utf8)!
let obj = try? JSONDecoder().decode(Foo.self, from: json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment