title: How to cast 'Class A' to its subclass 'Class B' - Objective-C
body: <p>I'm using a framework which defines and uses 'ClassA', a subclass of NSObject. I would like to add some variables and functionality so naturally I created 'ClassB', a subclass of 'ClassA'</p>
  
  <p>Now my problem is this. Many of the methods within this framework return instances of 'ClassA' which I would like to cast to my subclass. </p>
  
  <p>For example take this method:</p>
  
  <pre><code>- (ClassA *)doSomethingCool:(int)howCool
  </code></pre>
  
  <p>Now in my code I try this:</p>
  
  <pre><code>ClassB * objB;
  objB = (ClassB *)doSomethingCool(10); 
  
  NSLog(@"objB className = %@", [objB className]);
  </code></pre>
  
  <p>This runs just fine. No compile or runtime errors or anything. But what is really odd to me is the output:</p>
  
  <pre><code>&gt;&gt; "objB className = ClassA"
  </code></pre>
  
  <p>The casting obviously failed. Not sure what's happened at this point... objB is typed as 'ClassB', but it's className is 'ClassA' and it won't respond to any 'ClassB' methods.</p>
  
  <p>Not sure how this is possible... Anyone know what I am doing wrong here?</p>
  
  <p>I found a similar post which is exact opposite of what I'm asking <a href="https://stackoverflow.com/questions/988842/is-it-possible-to-downgrade-an-object-in-objective-c-to-its-superclass">here</a></p>