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 638209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:42:27+00:00 2026-05-13T20:42:27+00:00

this is kind of a beginners question so please bear with me. I’ve got

  • 0

this is kind of a beginners question so please bear with me.

I’ve got a class that makes use of a third-party library (oniguruma, if that matters). I want library methods to be completely decorated by my own, so that I can switch the underlying implementation of my class anytime. Something like:

// MyClass.h

@interface MyClass : NSObject ...

- (int) doSomething;


// MyClass.m

#import "some_library.h"

@implementation MyClass

- (int) doSomething 
{
   //call library's specific stuff
}

So far, so good, but now I’m needing to use an instance variable in MyClass that has some library-defined type (a structure declared in “some_library.h”). Of course I can import the library right in the interface section:

//MyClass.h

#import "some_library.h"

@interface MyClass : NSObject {
    some_library_t blah;
}
- (int) doSomething;
@end

but this is exactly what i’m trying to avoid – make users of MyClass aware of its implementation details.

Can I somehow “hide” library-specific types from my class’ interface? What is the standard practice?

  • 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-13T20:42:27+00:00Added an answer on May 13, 2026 at 8:42 pm

    The standard practice is to use opaque pointers to either the library types or a custom implementation structure (thus its also called Pimpl – pointer to implementation).

    To do that you have to know that you can define pointers to incomplete types, i.e. types that you only declare to exist. E.g.:

    struct FooImpl;
    
    @interface Foo {
        struct FooImpl* impl; // using pointer is ok for incomplete types
    }        
    @end
    

    You can then define the type in the implementation file:

    struct FooImpl {
        // ... member definition
    };
    

    and allocate/initialize it e.g. in your -(id)init method.

    FooImpl could also be SomeLibraryType if the library type was a struct – you’d then forward declare it in the same way and include the library header in the source file, which gives you the structs definition.

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

Sidebar

Related Questions

I know this is kind of a beginners question but my books aren't explaining
this kind of follows on from another question of mine. Basically, once I have
this kind of emergency, so please, can someone help me... I'm using movingboxes plugin
I have ask this kind of question before, but it seems my previous question
I am sure that this kind of questions must have been asked before, but
This is kind of a beginner's question but the code I am looking at
This is kind of a beginner question. For now I have the implementation like
This kind of code would normally work in PHP, but since the scope is
This was the first time I encountered this kind of error after dealing with
I have this kind of recrods: 1 2 12345 2 4 98231 ... I

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.