Reputation: 55643
I've got an NSMutableDictionary (p) - via a JSON string - that has a bunch of dates in it (seconds since the epoch). I want to convert them to NSDate. I tried the following:
NSDate *created_dt = [NSDate dateWithTimeIntervalSince1970:[p objectForKey:@"created_dt"]];
But I get "sending 'id' to parameter of incompatible type 'NSTimeInveral' (aka 'double')"
What's the syntax that I am missing?
Thanks!
Upvotes: 1
Views: 73
Reputation: 16946
dateWithTimeIntervalSince1970:
expects an NSTimeInterval
(which typedef
ed to a double
). You pass it an object (the return value of objectForKey
). This object is probably an NSNumber, so you can simply solve your problem like this:
NSDate *created_dt = [NSDate dateWithTimeIntervalSince1970:[[p objectForKey:@"created_dt"] doubleValue]];
Upvotes: 2