iOS Build a Weather App Refactoring Using Codable Recap: Refactoring Using Codable

Christian A. Castro
Christian A. Castro
19,776 Points

Complete the blanks to make the nested enum a valid CodingKey conforming type!!! Help please!!!!

Any idea why is not taking the answer!?? The answer should be case model = "model"

import Foundation

struct Vehicle: Codable {
    let model: String

    enum CodingKeys: String, CodingKey 
 {
        case model = "model"
    }
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Staff

Hi there, Christian A. Castro ! I thought that, too. In fact, I was stuck on this one question of this quiz for a while. Then I went out to the Apple Developer documentation here

And I found this:

If the keys used in your serialized data format don't match the property names from your data type, provide alternative keys by specifying String as the raw-value type for the CodingKeys enumeration. The string you use as a raw value for each enumeration case is the key name used during encoding and decoding. The association between the case name and its raw value lets you name your data structures according to the Swift API Design Guidelines rather than having to match the names, punctuation, and capitalization of the serialization format you're modeling.

Now, this might sound like a lot, but take a look at the example below that. You'll see that you're actually putting a bit too much information here.

It's not:

case model = "model"

It's just:

case model

Hope this helps! :sparkles:

Christian A. Castro
Christian A. Castro
19,776 Points

Jennifer Nordell Thank you so much!! I really appreciate the time you took to answer my question. Have a wonderful day, bless!! Thank you again!