Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialising 'double' with an expression of incompatible type 'id'

Im trying to assign a value to a double, using the following code:

double distanceFormat = [self.runsArray[indexPath.row] valueForKey:@"runDistance"];

But I keep getting the following error:

Initialising 'double' with an expression of incompatible type 'id'

However, I know the value is a double! Is there a way to do this?

like image 776
Alex Godbehere Avatar asked Sep 25 '12 21:09

Alex Godbehere


2 Answers

Could you try with:

double distanceFormat = [[self.runsArray[indexPath.row] valueForKey:@"runDistance"] doubleValue];

If you're sure it is double I think it would work.

like image 152
CSolanaM Avatar answered Oct 20 '22 00:10

CSolanaM


Use NSNumber

NSNumber *mynumber = [somedictionary valueForKey:@"runDistance"];

Once you have the nsnumber, you can convert it into whatever you want, f.ex :

int i = [mynumber intValue];
like image 36
Trausti Thor Avatar answered Oct 20 '22 00:10

Trausti Thor