Alex
Alex

Reputation: 3072

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?

Upvotes: 8

Views: 14131

Answers (2)

Trausti Thor
Trausti Thor

Reputation: 3774

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];

Upvotes: 7

CSolanaM
CSolanaM

Reputation: 3368

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.

Upvotes: 14

Related Questions