How can i properly change the following into a NSInteger:
countDown.text = [NSString stringWithFormat:@"%i", (int)(currentTime-startTime)];
Countdown is a SKLabelnode
How can i properly change the following into a NSInteger:
countDown.text = [NSString stringWithFormat:@"%i", (int)(currentTime-startTime)];
Countdown is a SKLabelnode
There's no real benefit to casting to an NSInteger
(which is just a typedef
for long
on 64-bit architectures and int
on 32-bit architectures) , but you can do that by changing your code into the following:
countDown.text = [NSString stringWithFormat:@"%ld", (NSInteger)(currentTime-startTime)];
You could use NSNumberFormatter
For example:
NSString *string = @"12";
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSInteger i = [[formatter numberFromString:string] integerValue];