Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Christian A. Castro
Christian A. Castro
23,601 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 Teacher

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
23,601 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!