Skip to content

How to handle Default values? #17

@mbalex99

Description

@mbalex99

What if I have a declaration of a struct like this?

struct Person {
    var firstName: String = "Max"
    var lastName: String = "Alexander"
    var age: Int = 12
    var phoneNumber: String = "4159300285"
}

But then I try to construct it using:

let person: Person = try! construct(dictionary: [:])

It'll tell me there are missing keys from the input dictionary. I understand the error. But what if the keys are missing and I prefer to construct it with their default values that I have declared above?

Is there any way to handle this sort of behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions