SwiftUI · DatePicker & Toggle | raywenderlich.com

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4001741-swiftui/lessons/10

Why do we need to make the @State variable private? I can understand that @State is to make the view to synchronise with the variable. But how about the “private” part?

Hey. So that parent views cannot mutate it. State should be private to the view that they affect. We got over this in the course as well. Laurie.

Hi, my “Select Date” text is not laying out properly (on Canvas or actual device). I’ve attached a screenshot of the the problem (running on iPhone SE 2020 in dark mode) as well as the code. Any idea as to why this problem is occurring?

Screen Shot 2020-05-18 at 11.02.21 PM

Screen Shot 2020-05-18 at 11.04.17 PM

Hey, I could be wrong about this but I believe it’s a fairly new addition to SwiftUI and you need to pass it a date component style modifier. See here for stuff to try out: Apple Developer Documentation

I cannot understand here what is ‘DatePicker.Components’ in the date picker initializer. Could you please help?

@shrutisharma yes the date components concerns the formatting of the displayed date. Currently we can show the date or the hourAndMinute. One shows the full date and the other would show the time so-to-speak. Currently the documentation isn’t super-helpful but hopefully that is clear. Take care! Laurie.