views:

170

answers:

1

I'm creating a static library to share using the following guide: http://www.amateurinmotion.com/articles/2009/02/08/creating-a-static-library-for-iphone.html

In one of the functions, I return a "SomeUIView" which is a subclass of UIView and is defined in the public header, however I don't want to expose the internal instance variable of SomeUIView in the public header.

I've tried using categories for a private internal header file for SomeUIView, but I keep running into "Duplicate interface declaration for class 'SomeUIView'".

Does anyone know how to do this?

Thanks!

+2  A: 

Categories and extensions can't add instance variables to a class. I'd go for the PIMPL idiom here - use a private implementation object:

// header
@class MyObjImpl;
@interface MyObj {
    MyObjImpl* impl;
}
@end

// implementation file:
@interface MyObjImpl {
    id someIvar;
}
// ...
@end

// ... etc.

This also keeps your public interface stable in case you want to add something for internal use.

The "duplicate interface" comes from missing parentheses in the second interface declaration:

// header:
@interface MyObj 
// ...
@end

// implementation file:
@interface MyObj () // not the parentheses which make it a class extension
// ...
@end
Georg Fritzsche
Note that a private implementation (a PIMPLE... my second favorite acronym next to NARC), won't actually hide the ivars... you can still get at 'em if you dig enough at runtime.
bbum