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

selected date as Nullable #264

Closed
danielCarlosCE opened this issue Apr 12, 2016 · 7 comments
Closed

selected date as Nullable #264

danielCarlosCE opened this issue Apr 12, 2016 · 7 comments

Comments

@danielCarlosCE
Copy link

I was trying to use selectedDate, but at some point at time, that property was nil. I couldn't prevent the crash since when ported to Swift, that property is of the type NSDate instead of NSDate?

@WenchaoD
Copy link
Owner

WenchaoD commented Apr 15, 2016

Hi @danielCarlosCE
Before selectDate:date, make an optional binding

if let dateNonNull = yourDate {
    calendar.selectDate(dateNonNull)
}

@danielCarlosCE
Copy link
Author

That's what I did, thanks. However, wouldn't be better knowing in compile time? I didn't know it could be nil until I actually got an error in run time.

@WenchaoD
Copy link
Owner

Of course it's a compile-time stuff. There is already a nonnull prefix.
image

@ashhanai
Copy link

ashhanai commented Nov 9, 2016

Hello, I am wondering why is selectedDate Date type, instead of optional Date (Date?). I am running to run time error, when user hadn't select any date (or after calling deselect(_:)) and the selectedDate property is crashing my app.

I would use optional binding to check if there is selected date or not, but there is no optional to bind.

@danielCarlosCE
Copy link
Author

That was my point @ashhanai . I only find out that it could be nil when my code broken on production.

@ashhanai
Copy link

ashhanai commented Nov 9, 2016

So if I understand it right, if I filter items depending of selected date, I cannot let user not to select any date, right? And if I ask for selected date and user doesn't have any, it will crash.

My proposal is to make selectedDate optional as it can be nil, when user does not have any selected date.

@WenchaoD
Copy link
Owner

WenchaoD commented Nov 9, 2016

@ashhanai The crash has been prevented. But I'll make it optional, thanks for the proposal:)

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

3 participants