Hi, thanks for writing this up!
Evan Roth
51

Hello Evan,

This is great question and it got me thinking for a while. Thank you for that :]

Though finally I was able to come up with something. The deal here is that we cannot use Person initializer to initialize a Person array ([Person]) since they are different types. What we can do is, we can write the same initializer for Person array in an extension. It goes something like this:

extension Array where Iterator.Element == Person {
init?(jsonString: String) {
guard let data = jsonString.data(using: .utf8) else {
return nil
}
    self = try! JSONDecoder().decode([Person].self, from: data)
}
}

Then we can go ahead and initialize as the following:

let people = [Person](jsonString: jsonString)

I hope this helps!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.