Nat! bio photo

Nat!

Senior Mull.

Twitter RSS

Github

NSCalendar warning message never fails to annoy me

This warning message from the depths of Foundation never fails to annoy me:

MulleCalendarReloaded[1197:c07] *** -[__NSCFCalendar components:fromDate:toDate:options:]: toDate cannot be nil
I mean really, what do you think that operation is supposed to mean with a nil toDate?
An exception has been avoided for now.
A few of these errors are going to be reported with this complaint, then further violations will simply silently do whatever random thing results from the nil.
Here is the backtrace where this occurred this time (some frames may be missing due to compiler optimizations):

Some random newb coder at Apple picked unfailingly the worst solution out of the possible four choices:

  1. Just extract your 0.0 NSTimeInterval from the NSDate nil and get on with it. This is what I'd expect, this being Objective-C after all.
  2. Return nil. That's the way to indicate that something went wrong, without raising an exception.
  3. Raise. If you feel really strongly about it.
  4. Be as vague and whiny as possible about it. Avoid making a decision.