On Jul 29, 2008, at 8:22 PM, Torsten Curdt wrote:

So how can I have private ivars that don't show up in the interface?

You can use the pImpl (pointer-to-implementation) idiom for classes that you're writing yourself:

@class MyPrivateStuff;
@interface MyClass : NSObject
{
        MyPrivateStuff* pImpl;
}

/* ... */

@end


Then, in your .m file:

@interface MyPrivateStuff : NSObject
{
        id foo;
        NSString* bar;
        /* ... */
};
@end

@implementation MyPrivateStuff
/* ... */
@end

@implementation MyClass

- (id) init
{
        if (self = [super init])
        {
                pImpl = [[MyPrivateStuff alloc] init];
                /* ... */
        }
}

@end



For classes which you are not writing yourself, you can still extend them with categories. For properties, you add the usual accessor methods, which is straightforward with a category. Providing per- instance backing storage for the properties is more complicated. One technique is to use a "category variable" (like the "class variable" we were discussing earlier; really just a static file-scope variable) to keep an associative collection which maps from "self" to a mutable dictionary of property values. NSMapTable is a good candidate for this sort of collection.

Cheers,
Ken
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to