Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle Default values? #17

Open
mbalex99 opened this issue Oct 16, 2018 · 0 comments
Open

How to handle Default values? #17

mbalex99 opened this issue Oct 16, 2018 · 0 comments

Comments

@mbalex99
Copy link

mbalex99 commented Oct 16, 2018

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant