It is a matter of integer overflow, as Boris correctly pointed out in his answer.
I don't know what your time
object is, but instead of a signed long int
use a NSTimeInterval
.
On iOS NSTimeInterval
is currently defined as
typedef double NSTimeInterval;
but you shouldn't care too much about that. Sticking with type synonyms will protect you in case Apple decides to change the underlying definition to something else.
That said you should change your code to something like
NSTimeInterval epoch = [time doubleValue];
NSDate * date = [NSDate dateWithTimeIntervalSince1970:epoch];
Concerning the code maintainability issue I described before, here you are explicitly using a doubleValue
(you don't have many options), but the good thing is that if Apple changes the NSTimeInterval
definition to something not compatible with a double
assignment, the compiler will let you know.