title: Objective-C Redefine Class
body: <p>I have some Code that I'd like to share between an iOS and an OSX project. Unfortunately, some classes, while functionally relatively similar (and having greatly overlapping interface definitions), are parts of different hierarchies and frameworks, and have different names. UIKit/AppKit classes are a prime example.</p>
  
  <p>One solution would be to use preprocessor directives, but that creates a lot of duplicate code:</p>
  
  <pre><code>#if TARGET_OS_IPHONE
    - (UIImage *)getImage; //have to create an implementation for each
  #else
    - (NSImage *)getImage; //have to create an implementation for each
  #endif;
  </code></pre>
  
  <p>I had thought about using reflection. In Objective-C, it's possible to dynamically get a Class object with the use of <code>NSClassFromString(@"name")</code>. This is very nice, but if used often, creates ugly code. It also can't be used in a header file, because it's not constant, so this does not work:</p>
  
  <pre><code>//defined once per project
  #if TARGET_OS_IPHONE
    Class NUImage = NSClassFromString(@"UIImage");
  #else
    Class NUImage = NSClassFromString(@"NSImage");
  #endif;
  
  //usage
  - (NUImage *)getImage; //does not compile
  </code></pre>
  
  <p><strong>I want to be able to define (ideally at compile time) a Class Synonym, so that it can be used transparently in place of the specific implementation class. Is this possible? In essence, I want to avoid having to write a wrapper class</strong> (which would either just forward messages to the concrete implementation, thus be easy to write but take away code completion and checking, or be a lot of boilerplate code just to duplicate the interface of the class(es) it's wrapping).</p>
  
  <p>Is it possible to store the Class as a constant?</p>