See also macOS
Preflight possible universal links before opening SFSafariController
Before you open a URL in SFSafariController or any other browser, you should check if it’s a universal link,
and if so, open it in the respective native app instead.
It’s a good way to improve the user experience since SFSafariController will not trigger universal links on open.
let url = URL(string: "https://youtu.be/k0kSc8hHzAM?t=1461")!
UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { (success) in
if !success {
// not a universal link or app not installed
let vc = SFSafariViewController(url: url)
self.present(vc, animated: true)
}
}
xcrun simctl
tool.DateFormatter
?The key take away from all these stats are:
DateFormatter
is expensive to create.DateFormatter
is expensive to change.- Subsequent use of
string(from: Date)
is cheap.- Subsequent use of
date(from: String)
is not cheap.
This is slightly misleading, though. Despite what the preview shows,
Date
has no concept of days, months, years, any of that stuff. It deals solely with time, and more specifically, the number of seconds that have passed since midnight of 1 January 2001, in UTC.[...]
Here’s a screenshot from the Health app, showing my step counts for the day of June 8, 2017. It was a fairly active day, as I got in a bit over 20,000 steps. The distribution of those steps, though, feels a bit off. It reads like I was up walking all night, and then asleep throughout the day, and scrolling around a bit, that’s the story for the rest of the week too. I don’t remember spending the week that way.
As it happens I was in San Jose attending WWDC at the time, which has a -12:30 time difference with India , and as a result all of my health data from that trip appears time-shifted.
[...]
Going back to how
Date
works, it doesn’t model the actual clock time but rather a fixed point in time that can be interpreted in any time zone. And so what’s happening here is that the data is being interpreted as if it happened in my current time zone, which is the default time zone thatCalendar
andDateFormatter
use.And as such, a
Date
alone isn’t sufficient for modelling historical data, or at least personal historical data: You need time zone information too.
Last modified 07 October 2024