How do I find really detailed information about changes?


(Eric Miller) #1

I'm working on migrating from Swift 2.3 to Swift 3.0.

Sometimes I can't get as much info about a change as I like. I'm aware of
the swift-evolution github repo and can search that. Swift.org's migration
guide is also really helpful.

I'm now trying to find why, along with changing from NSCalendar to
Calendar, the .components are optional. I can't find any mention of it, and
I'm not sure in what situation minutes or hours could be nil and how I
should guard against it.

Is there a way to search the evolution mailing list, or is there a better
place to search?


(Kevin Nattinger) #2

I could be wrong (haven’t tested, but my impression is that only components you explicitly request in the option set passed to calendar.components will be non-nil.

···

On Jun 22, 2016, at 9:49 AM, Eric Miller via swift-users <swift-users@swift.org> wrote:

I'm working on migrating from Swift 2.3 to Swift 3.0.

Sometimes I can't get as much info about a change as I like. I'm aware of the swift-evolution github repo and can search that. Swift.org's migration guide is also really helpful.

I'm now trying to find why, along with changing from NSCalendar to Calendar, the .components are optional. I can't find any mention of it, and I'm not sure in what situation minutes or hours could be nil and how I should guard against it.

Is there a way to search the evolution mailing list, or is there a better place to search?
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Brent Royal-Gordon) #3

I'm now trying to find why, along with changing from NSCalendar to Calendar, the .components are optional. I can't find any mention of it, and I'm not sure in what situation minutes or hours could be nil and how I should guard against it.

In Objective-C, these properties can be `NSUndefinedDateComponent`. In Swift, that's represented as `nil` instead.

Essentially, this happens when you don't request a particular date component—for instance, when you say `gregorian.components([.year, .month, .day], fromDate: date)`, `hours` and `minutes` will be `nil`. In Objective-C, they would have been `NSUndefinedDateComponent`.

···

--
Brent Royal-Gordon
Architechies


(Eric Miller) #4

I think there's an API change here that isn't acknowledged, I was just
trying to figure out what happened, and how I can investigate them in the
future.

Maybe the answer is I can get lots of detail about Swift core changes, but
what Apple does with the standard library is a little less transparent.

code:

    let start = calendar.components([.hour, .minute], from:
Date(timeIntervalSince1970: TimeInterval(start/1000)))
    from = Int64(( (start.hour ?? 0) * 3600 + (start.minute ?? 0) * 60) *
1000)

There are some minor signature changes accounted for by the lowercase enum
and the param naming changes, that's expected.

Component usage now requires the ?? operator but didn't used to. The return
value of calendar.components is a tuple with optional parts. In Swift 2.3,
this wasn't so.

This could be a knock on effect from
https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md,
which talks about dropping conformance to NilLiteralConvertible, except
NSUndefinedDateComponent isn't mentioned as one of them and the topic is
otherwise unrelated.

It also could be a consequence of
https://github.com/apple/swift-evolution/blob/master/proposals/0054-abolish-iuo.md
-- My functions can no longer return implicitly unwrapped optionals and
perhaps that's how calendar.components was implemented.

···

On Wed, Jun 22, 2016 at 4:13 PM, Brent Royal-Gordon <brent@architechies.com> wrote:

> I'm now trying to find why, along with changing from NSCalendar to
Calendar, the .components are optional. I can't find any mention of it, and
I'm not sure in what situation minutes or hours could be nil and how I
should guard against it.

In Objective-C, these properties can be `NSUndefinedDateComponent`. In
Swift, that's represented as `nil` instead.

Essentially, this happens when you don't request a particular date
component—for instance, when you say `gregorian.components([.year, .month,
.day], fromDate: date)`, `hours` and `minutes` will be `nil`. In
Objective-C, they would have been `NSUndefinedDateComponent`.

--
Brent Royal-Gordon
Architechies