Re: private methods and variables
Re: private methods and variables
- Subject: Re: private methods and variables
- From: Jean-Daniel Dupas <email@hidden>
- Date: Wed, 30 Jul 2008 12:18:40 +0200
Le 30 juil. 08 à 11:26, Torsten Curdt a écrit :
Where does it say that protocols can't include class methods? If
there is documentation indicating as much then there is a bug
somewhere and I'd like to know about it.
The following works as expected -- the compiler complains mightily
about the lack of conformance to protocol Bob in class Fred.
@protocol Bob
+ (void) foo;
@end
@interface Fred : NSObject <Bob>
@end
@implementation Fred
@end
Got it working now!
I had
@protocol Bob
+ (Bob *)sharedBob; // error: syntax error before 'Bob'
@end // warning: '@end' must appear in an @implementation context
@interface Fred : NSObject <Bob>
...
@end
but it needs to be:
@protocol Bob
+ (NSObject<Bob> *)sharedBob;
@end
However, protocols are not generally used to hide implementation
details. It sounds more like you want a combination of public and
private headers / declarations.
Definitely sounds like that. Basically I have a framework entry
(public header)
@interface Bob {
@private
some ivars here
}
+ (Bob *)sharedBob;
- (void)someMethods;
@end
And I would rather have it look like this in public.
@interface Bob
+ (Bob *)sharedBob;
- (void)someMethods;
@end
Still I need those ivars in private though.
For Cocoa, functionality that is supported is made available
through public headers. Functionality that is internal to Cocoa is
encapsulated in private headers that declare said private
interfaces through a combination of categories, class extensions
and full-on class declarations.
Any pointers on how this is done?
cheers
--
Torsten
The true question is why you need this ?
I don't see any valid reason to require this kind of constraint.
Now, if you really want something like this, I bet the cleaner way is
to use class cluster, but it will prevent your framework user to
subclass Bob.
An other common way is to hide your ivar in an opaque struct (or
another object with forward declaration only):
@interface Bob {
@private
struct __OpaqueBobIVars *ivars;
}
+ (Bob *)sharedBob;
- (void)someMethods;
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden