title: iOS Xcode: Compiler error accessing Ivar in Objective-C
body: <p>I am working in a large existing objective-c codebase, writing unit tests at the moment. The project uses instance variables widely.</p>
  
  <p>I wrote a little method to grab the ivar for something. It worked in another unit test in the same project, but isn't working in this case.</p>
  
  <p>Code:</p>
  
  <pre><code>-(id)getObjectForIvarNamed:(NSString *)ivarNameString
   {
      const char *ivarName = [ivarNameString UTF8String];
  
      Ivar ivarValue = class_getInstanceVariable([textFieldOverlay class], ivarName);
      id objectAtIvar = object_getIvar(textFieldOverlay, ivarValue);
  
      return objectAtIvar;
  }
  </code></pre>
  
  <p>The compiler complains at the line starting <code>Ivar ivarValue</code> with the following error:</p>
  
  <p><code>"Declaration of 'Ivar' must be imported from module 'ObjectiveC.runtime' before it is required"</code></p>
  
  <p>A web search for this error code comes up with zero hits. Not sure why it works in another file, the headers all look the same between the two <code>XCUnitTest</code> classes.</p>