title: Objective-C wrapper API design methodology
body: <p>I know there's no one answer to this question, but I'd like to get people's thoughts on how they would approach the situation.</p>
  
  <p>I'm writing an Objective-C wrapper to a C library. My goals are:</p>
  
  <p>1)  The wrapper use Objective-C objects.  For example, if the C API defines a parameter such as char *name, the Objective-C API should use name:(NSString *).</p>
  
  <p>2)  The client using the Objective-C wrapper should not have to have knowledge of the inner-workings of the C library.</p>
  
  <p>Speed is not really any issue.</p>
  
  <p>That's all easy with simple parameters.  It's certainly no problem to take in an NSString and convert it to a C string to pass it to the C library.</p>
  
  <p>My indecision comes in when complex structures are involved.  </p>
  
  <p>Let's say you have:</p>
  
  <pre><code>struct flow
  {
      long direction;
      long speed;
      long disruption;
      long start;
      long stop;
  } flow_t;
  
  And then your C API call is:
  
  void setFlows(flow_t inFlows[4]);
  </code></pre>
  
  <p>So, some of the choices are:<br>
  1) expose the flow_t structure to the client and have the Objective-C API take an array of those structures<br>
  2) build an NSArray of four NSDictionaries containing the properties and pass that as a parameter<br>
  3) create an NSArray of four "Flow" objects containing the structure's properties and pass that as a parameter  </p>
  
  <p>My analysis of the approaches:<br>
  Approach 1:  Easiest.  However, it doesn't meet the design goals<br>
  Approach 2:  For some reason, this seems to me to be the most "Objective-C" way of doing it.  However, each element of the NSDictionary would have to be wrapped in an NSNumber.  Now it seems like we're doing an awful lot just to pass the equivalent of a struct.<br>
  Approach 3:  Seems the cleanest to me from an object-oriented standpoint and the extra encapsulation could come in handy later.  However, like #2, it now seems like we're doing an awful lot (creating an array, creating and initializing objects) just to pass a struct.  </p>
  
  <p>So, the question is, how would you approach this situation?  Are there other choices I'm not considering?  Are there additional advantages or disadvantages to the approaches I've presented that I'm not considering?</p>