5

DispatchTime and (NS)Date have the property distantFuture, which "returns a time in the distant future."

Discussion:

You can pass this value to methods that schedule work to have the system wait indefinitely for a particular event to occur or condition to be met.

I can't think of or find an example where I would actually need to use this. What is a good use case?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
mmd1080
  • 1,812
  • 2
  • 17
  • 29
  • 2
    Why not [search on distanceFuture](https://stackoverflow.com/search?q=%5Bswift%5D+distantFuture) to find examples? [Searching on distantPast](https://stackoverflow.com/search?q=%5Bswift%5D+distantPast) helps too. – rmaddy May 29 '17 at 21:03
  • 3
    See https://stackoverflow.com/a/44144424/1226963 for a recent example using `distantPast`. – rmaddy May 29 '17 at 21:04
  • @rmaddy I did search and just wasn't satisfied with what I found. I haven't ever needed to make a synchronous HTTP request for instance (thought to be fair that question has been viewed 16913 times!) – mmd1080 May 29 '17 at 22:27

2 Answers2

16

For example if you want to retrieve future events from a calendar with an unspecified end date.

In this case you can set the end date of the predicate to distantFuture.

vadian
  • 274,689
  • 30
  • 353
  • 361
3

Here's an example what unspecific dates will be returned:

let date = Date()
// current, here: "Sep 30, 2020 at 9:27 AM"

let distantPast = Date.distantPast
// "Jan 1, 1 at 12:53 AM"

let distantFuture = Date.distantFuture
// "Jan 1, 4001 at 1:00 AM"
SchmidtFx
  • 498
  • 4
  • 16