My apologies… My mystake. Your code appears sound.
Frederick C. Lee
2

Here’s a quick untested solution I’m thinking about. I’ve added an ‘unknown’ case and followed thru. Then you’ll have an incomplete switch stmt hence the ‘default’ to process the ‘unknown’.

enum Character {

case hero(Hero) // …Associated Types

case princess(Princess)

case civilian(Civilian)

case unknown

private enum CharType : String {

case hero, princess, civilian, unknown

static let key = “type” // Note: enums can’t have stored properties; hence ‘static’.

}

init?(json: [String : AnyObject]) {

guard let

string = json[CharType.key] as? String,

type = CharType(rawValue: string)

else { return nil }

switch type {

case .hero:

guard let hero = Hero(json: json) else { return nil }

self = .hero(hero)

case .princess:

guard let princess = Princess(json: json) else { return nil }

self = .princess(princess)

case .civilian:

guard let civilian = Civilian(json: json) else { return nil }

self = .civilian(civilian)

default:

print(“Unknown”)

self = .unknown

}

}

}

One clap, two clap, three clap, forty?

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