---
title: "How to cast id into a float?"  
description: "How to cast id into a float?"  
author: "Tarun Kumar"  
published: 2015-09-22  
updated: 2015-09-23  
canonical: https://www.mindstick.com/forum/33466/how-to-cast-id-into-a-float  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# How to cast id into a float?

I write a [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) and getting [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) with this code:

```
NSRect myFrame;id item;
```

// for assigning code to [item](https://www.mindstick.com/forum/156564/remove-item-in-an-array-in-javascript)

```
myFrame.origin.y -= [item respondsToSelector:@selector(myHeight)] ? [item myHeight]   : [self defaultMyHeight];
```

Here is the problem:

```
[item myHeight]
```

The [compiler](https://www.mindstick.com/articles/27/just-in-time-compiler) is assuming that the return type is id. So, I thought that by using type [cast](https://answers.mindstick.com/qa/97273/how-to-cast-a-baitcaster) I would [fix](https://yourviews.mindstick.com/view/80763/donald-trump-ki-jeet-fix-hai) this:

```
(float)[item myHeight]
```

but it’s not working.

So, I’m not [understanding](https://www.mindstick.com/articles/12918/cat-5e-vs-cat-6a-understanding-the-major-differences) that what amoing wrong.oing wrong. I [doing wrong](https://answers.mindstick.com/qa/36736/what-are-indians-doing-wrong-on-whatsapp).

## Replies

### Reply by Anonymous User

The compiler makes that kind of assumptions when multiple classes declare methods with the same name, that return different types. Since your "item" variable is typed as an "id," the compiler doesn't know which of these classes it will be sending the message to at run time, and chooses one.

To avoid this problem, you can inform the compiler what class "item" is an instance of, by declaring it with a specific type instead of the generic "id":

SomeItemClass *item;

You could also avoid it by not declaring identically-named methods that return different types.


---

Original Source: https://www.mindstick.com/forum/33466/how-to-cast-id-into-a-float

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
