简体   繁体   中英

Is this enum of two different types?

I'm following a tutorial and I noticed the author(s) declared this enum with what looks like to be multiple types. Based on what I've read online from the Swift Standard Library, I understand enums can be of a certain type and enums do not support inheritance. Is this enum of both String and CodingKey type? Or is the name case a String type and the items case a CodingKey type?

private enum CodingKeys: String, CodingKey {
        case name
        case items
    }

This isn't inheritance, it's two things:

  1. A raw value clause . This is a special form that speficies the "backing value" used to represent the enum 's cases. In this case, it's String . When an enum has chosen to have a String raw value, but the case doesn't specify a raw value, the name of the case is implicitly assumed to be the raw value of the case.
  2. A protocol conformance clause, which declares that this enum conforms to CodingKey .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM