0

I am writing a obj-c fake library for iphone. I need to deploy the library to my client for project perpose, but I don't want any vialation of my property. I want to give a single header file along with the library which can be used by my client. But problem is something like: My Class A extends class B, class B extends class C. I want to give the header of class A (file A.h) to client, But there's code like "import B.h" in "A.h", so if I do not expose my B.h, It won't compile in my client's project, And so as class C and furthor deep base classes. And I can't expose these classes cause these would expose all of my structures and leads vialations of my property. Please help and thanks a lot.

1
  • Hi, Caleb, Thanks for helping. But it seems that @class keyword can't be used for a base class, this gonna report a compile error in xcode. Commented Nov 27, 2013 at 16:55

1 Answer 1

1

As stated in the comments to Caleb's answer, a class has to be able to see the @interface of its superclass.

But here is what you can do. The interface for ClassB can be pretty much empty, except for the designated initialiser. You can then put all of your internal-to-your-library properties and methods in a category in a separate header file. e.g.

// ClassA.h --------------------- #import "ClassB.h" @interface ClassA : ClassB // stuff @end // ClassB.h --------------------- @interface ClassB : NSObject // Properties and methods on ClassB that really are public (possibly none). @end // ClassB+Internal.h --------------------- #import "ClassB.h" @interface ClassB(Internal) // "Internal" can be anything you like @property (copy) NSString* mySecretProperty; // etc @end // ClassB.m --------------------- @interface ClassB() // Class extension // Really secret properties and methods not to be seen outside of this file. @property (copy) NSString* myReallySecretProperty; @end @implementation ClassB @synthesize mySecretProperty; @end 

Normally you would create an implementation for the Internal category, but you don't actually need to as long as the methods exist at runtime.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you JeremyP, This is a good idea. I am working on it to change my structure into this design pattern.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.