views:

42

answers:

2

I am trying to define the equivalent of DateTime.MaxValue (C#) but in Objective C.

I don't want to keep creating NSDates every time I use it so I wish I had it as const.

The problem, the compiler returns "Initializer element is not constant"

Here is the code

static NSDate* DateTimeMinValue = [NSDateFormatter dateFromString:@"00:00:00.0000000, January 01, 1984"];

I also tried

NSDate* const DateTimeMinValue = [NSDateFormatter dateFromString:@"00:00:00.0000000, January 01, 1984"];

Also, what would the difference between the static and const be?

A: 

what would the difference between the static and const be?

Static variables exist for the life of the app's run session, and can be accessed and altered from within the class, or by other classes by way of accessors. Const variables cannot be modified.

Alex Reynolds
+1  A: 

While this is not the exact answer to your question it still might help you.
Did you ever read or hear about

[NSDate distantPast];
[NSDate distantFuture];

they return

An NSDate object representing a date in the distant future (in terms of centuries).

They come in quite handy when you have to compare dates to well a distant Date.

samsam