How can I convert a NSInteger to a NSTimeInterval

adrian picture adrian · Nov 7, 2011 · Viewed 12.7k times · Source

I have slideTimer which is a NSInteger and I want to convert it to NSTimeInterval.

I tried like this:

 NSTimeInterval slider = (NSTimeInterval)slideTimer;

but it is not working.Any idea?

Answer

bryanmac picture bryanmac · Nov 7, 2011

NSTimeInterval is just:

typedef double NSTimeInterval;

This code:

int i = 1500;
NSTimeInterval interval = i;
NSLog(@"%d", (int)interval);

Outputs:

2011-11-07 07:47:05.579 Craplet[7608:707] 1500

BTW, in XCode 4.2, hold down control and apple keys and types will have underlines. Click on that and you'll see the definition.