Comparing Dates, whilst ignoring the time

Comparing dates is one of the most common things you have to do as a developer of almost any type of software. At first glance it would seem to be something almost trivially easy. What could possibly go wrong? Well, turns out, quite a lot! I’m going to highlight just one issue that recently caused an embarassing bug in my app Memories. It involved just a simple date comparison, ignoring time, and without crossing timezones. »

Using stride to convert C-style for loops to Swift 2.2

With the release of Swift 2.2 in Xcode 7.3 C-style for loops have become deprecated. The default Xcode fix-it for converting them uses a Range: let count = 5 for var index = 0; index < count; index++ { doSomething(index) } is converted do: let count = 5 for index in 0 ..< count { doSomething(index) } For the vast majority of C-style for loops this will work perfectly well. But there are cases where using a Range not only won’t work as expected but will actually crash! »