<p>I'm having trouble with this code:</p>

<pre><code>NSRect itemFrame;
id item;
// code to assign item goes here.
itemFrame.origin.y -= [item respondsToSelector:@selector(selectedHeight)] ? [item selectedHeight]   : [self defaultSelectedHeight];
</code></pre>

<p>This is the problematic bit:</p>

<pre><code>[item selectedHeight]
</code></pre>

<p>The compiler is assuming that the return type is id. I though that adding a cast would fix this:</p>

<pre><code>(float)[item selectedHeight]
</code></pre>

<p>but it doesn't work. </p>

<p>What am I doing wrong? (I suspect the problem is to do with resolving pointers related to id but I can't find any relevant documentation).</p>

You need to look at the declaration of your
```
selectedHeight
```
method. The problem is either that the method is returning a pointer to an object (id), or you haven't imported the header file for
```
item
```
in the file that contains the code snippet, so Xcode assumes it's a pointer by default.
You can't cast a pointer to a float, since they're fundamentally incompatible types. Once you get your declarations straightened out though you should be okay.