TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Days 60: Consolidation - challenge completed (and a simple question)

Forums > 100 Days of SwiftUI


I managed to finish the challenge of day 60, it works well so I share if it interests someone to compare his method to mine and discuss it. Tomorrow, I have to add core data to it, so I share before 🙂

Just a question if anyone can enlighten me.

I just wonder why this :

class Someone: Decodable {
    let id: Int
    let name: String
    let age: Int

does not cause any error when there is no initialization ?

For my decodedObject in the challenge i used a struct, and not a class (everything works find), maybe i should do the challenge with a class, just to see if i will get there too.


Hi Maxime,

The class works because it inherits the default initializer from the Decodable protocol. If you remove the protocol, you will get the error Class 'Someone' has no initializers.

To be honest, I also used struct and not class. In my opinion you should always work with structs whereever possible and only with classes when it is really needed... And in this project, where we do not edit data and need multiple views share the same object (=identity), I stick with the struct.

Regards Philipp


Hi Philipp,

great, thank you! I thought it was something like that, thank you for this precision. I didn´t know that a class inherited from the initialization of its protocol, it's good to know.


o thank u man I'm int he same challenge and I don't know how to start, well i have an idea, but it doesn't work :(


I've put up my version of the challenge on GitHub:

Checkout the initial commit which is the state after day 60 has been implemented. I used:

struct User: Identifiable, Codable {
    let id: UUID
    let isActive: Bool
    let name: String
    let age: Int
    let company: String
    let email: String
    let address: String
    let about: String
    let registered: Date
    let tags: [String]

    struct Friend: Identifiable, Codable {
        let id: UUID
        let name: String

    let friends: [Friend]

to decode the file.


Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.