I am actually doing the tutorial of Paul Hudson’s 100 Days of Swift. I am currently at “Better Rest (Project 4)” and had some problems with his function.

Problem
We built this function, but didn’t use it.

func exampleDates() { 
    let tomorrow = Date.now.addingTimeInterval(86400) 
     
    let range = Date.now...tomorrow 
}

So I thought for myself, “how can I use it?” and tried to set it on my DatePicker.

DatePicker("Please enter a date", selection: $wakeUp,  
in: exampleDates())

I obviously got an error and asked myself “why?”.

Solution
The problem was that my function is not returning anything. So if you don’t return anything, the caller gets nothing back. So I went back to my function and added a return, but this wasn’t my solution, because Swift needs to know what the function should give back. That’s why you need to write in my case -> ClosedRange<Date>, because the in: parameter of my DatePicker expects a ClosedRange<Date>.

func exampleDates() -> ClosedRange<Date> { 
    let tomorrow = Date.now.addingTimeInterval(86400) 
     
    let range = Date.now...tomorrow 
     
    return range 
}