Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 664537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:36:38+00:00 2026-05-13T23:36:38+00:00

I know there’s no one answer to this question, but I’d like to get

  • 0

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.

I’m writing an Objective-C wrapper to a C library. My goals are:

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 *).

2) The client using the Objective-C wrapper should not have to have knowledge of the inner-workings of the C library.

Speed is not really any issue.

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.

My indecision comes in when complex structures are involved.

Let’s say you have:

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]);

So, some of the choices are:
1) expose the flow_t structure to the client and have the Objective-C API take an array of those structures
2) build an NSArray of four NSDictionaries containing the properties and pass that as a parameter
3) create an NSArray of four “Flow” objects containing the structure’s properties and pass that as a parameter

My analysis of the approaches:
Approach 1: Easiest. However, it doesn’t meet the design goals
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.
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.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:36:38+00:00Added an answer on May 13, 2026 at 11:36 pm

    I think that approach 3 would be the preferred way to do things. When you wrap a library you’ll want to create wrappers around any object or structure that the user is expected to deal with.

    If you wrap everything, then you are free to change the internal workings of your classes at a later date without affecting the interfaces that your users have become accustomed to. For example, in the future you may realize that you’d like to add some type of error checking or correction… maybe setting a stop that is earlier than the start causes some calculation errors, you could change the stop method in your Flow wrapper to set start equal to stop if stop is less than start (I admit, that’s a really bad example).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there exists a command like jQuery.noConflict. But for this it first registers
I know there have been a few threads on this before, but I have
I know there is a registry key indicating the install directory, but I don't
I know there are a lot of positive things mod-rewrite accomplishes. But are there
I know there are HTML entities for 1/2, 1/4, and 3/4, but are there
I know there are some ways to get notified when the page body has
I know there is a more readable way of writing this: var string =
I know there's a simple UIViewAnimationOptionTransitionFlipFromLeft and way to implement that, but how do
I know there are topics on this and I am aware of using Daemon
I know there are quite a few line count tools around. Is there something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.