Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Privately implementing a protocol? [duplicate]

Possible Duplicate:
Conforming protocol privately

A class of mine tries to register itself as the delegate to a NSXMLParser object that it creates. However, I don't think I want my class to publicly disclose that it implements the NSXMLParserDelegate protocol, since that NSXMLParser object is a private variable used only from within the class.

Am I right to avoid disclosing the protocol, and if so, how do I implement the protocol without making it public that the class does so?

like image 456
Mr. Smith Avatar asked Dec 19 '12 06:12

Mr. Smith


1 Answers

Try putting this in your .m file:

@interface MyClass (Private) <NSXMLParser>
@end

The specific category name (Private) doesn't matter – in fact you can use an empty set of parentheses (see below) – but I think this should require you to implement the required methods and tell the compiler that your class implements the protocol, at least in that file.

If that doesn't work, try simply removing <NSXMLParser> from your .h file, and casting self to id<NSXMLParser> if necessary, when setting the parser's delegate.

like image 141
paulmelnikow Avatar answered Nov 11 '22 04:11

paulmelnikow