Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert a NSInteger to a NSTimeInterval

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?

like image 805
adrian Avatar asked Nov 07 '11 12:11

adrian


2 Answers

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.

like image 173
bryanmac Avatar answered Oct 01 '22 10:10

bryanmac


In Swift:

let x: NSTimeInterval = NSTimeInterval(Int(123))
like image 35
King-Wizard Avatar answered Oct 01 '22 10:10

King-Wizard