Mike D Mike D - 9 months ago 30
Objective-C Question

Objective-C Method Call in Category Question

I have extended one of my classes with a category to deal with parsing a specific XML file.
In the class

I have defined method named
, which simply cycles through a list of items once the list has been built.

is declared in a private category declared inside

In my category,
, is where I call newsloop once the list has been built:

-(void) parserDidEndDocument: (NSXMLParser *)parser {
if ( [self.newslist count] >= 2 )
[self newsloop]; // warning flagged here
// to some other default stuff

Xcode (4, if it matters) shows a warning
Method '-newsloop' not found (return type defaults to 'id')

Why would cause a warning, since, if I'm right, categories have access to all the methods defined in the class they are extending.


The compiler still needs to know that the newsloop method (or selector) exists. When it's compiling your category file this method has not been declared anywhere so it will generate a warning.

If you want to keep this method private, you should create a ListBuilder+Private.h file where you declare any shared private methods, and include this in both ListBuilder.m and your ListBuilder+XMLParser category.

Technically users of your code can include the header themselves and also call the method, but there are other ways to do that anyway since there is no such thing as private/public methods in Objective-C. Also, including a header with 'Private' in it and calling methods is their problem, not yours.