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:
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. 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.