views:

5124

answers:

5

TurbineXMLParser.h

#import <Foundation/Foundation.h>

@interface TurbineXMLParser : NSObject <NSXMLParserDelegate> {
...

TurbineXMLParser.m

#import "TurbineXMLParser.h"

I have just added a new class to my current project that I previously tested in a single file. When I try and build the project I get the error: error: cannot find protocol declaration for 'NSXMLParserDelegate'

I did a bit of searching and tried adding the following ...

TurbineXMLParser.h

#import <Foundation/Foundation.h>

@protocol NSXMLParserDelegate;

@interface TurbineXMLParser : NSObject <NSXMLParserDelegate> {
...

but still get the warning: warning: no definition of protocol 'NSXMLParserDelegate' is found

any help would be much appreciated

.
.
.

EDIT_002:

Removing <NSXMLParserDelegate> from the @interface did work, but I am curious as to why, am I getting mixed up & muddled? I was under the impression that the delegate object must adopt the NSXMLParserDelegate protocol i.e. adding <NSXMLParserDelegate> after the superclass.

I have two instances where this is working differently, the first is a project in a single command line file where If I don't add <NSXMLParserDelegate> is warns that:

class 'TestXMLParser' does not implement the 'NSXMLParserDelegate' protocol

The second instance is where I have setup multiple *.h and *.m files (one of the classes being MyXMLParser.h, MyXMLParser.m) when I try to build the project with <NSXMLParserDelegate> I get this error:

error: cannot find protocol declaration for 'NSXMLParserDelegate'

Remove <NSXMLParserDelegate> and it all works fine, no errors, no warning...

gary

+5  A: 

You don't need to define your object to be an NSXMLParserDelegate

Just make sure you do this:

NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
[parser setDelegate:self];

And implement the methods in that object.

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
Felix Khazin
I have done exactly like what u said but in the 3rd delegate method i.e. parser: foundCharacters: I get null in the String whereas there is some value.
Jack
I have solved my problem.
Jack
This doesn't compile for me with a Base SDK of 4.1. The compile fails at setDelegate with "Class 'MyClass' does not implement the 'NSXMLParserDelegate' protocol". I can't find a way to make this build on both 3.2 and 4.1. Other posts suggest using a minimum OS version, but I want to be able to run on older handset OSes. http://stackoverflow.com/questions/2966475/nsxmlparserdelegate-compile-problem-iphone-sdk-30-vs-4-0
Dan J
Ah, I've just realized that the message I mention is a warning, not an error. I have the Xcode "treat warnings as errors" build option set, which explains why I am seeing the error.
Dan J
+3  A: 

Forward-declaring NSXMLParserDelegate isn't likely to help, it needs to be actually imported if you're conforming to it.

The original error is what you'd get if you haven't linked the Foundation framework into your project.

Get-info your target in XCode. In the General tab, make sure Foundation.framework is in your list of linked libraries.

Jeffrey Harris
The @protocol was just me trying things out, I now realise that its wrong. The Foundation framework not being found is what I thought, I probably set up a loop or missed it out completely, many thanks for the heads-up.
fuzzygoat
That line simply forward-declares the protocol, it doesn't define it as being empty. But of course the protocol needs to be defined at the point that it is used.
Mike Weller
Ah, I'd totally forgotten you could forward-declare a protocol, you're right. Editing to remove the question about that line.
Jeffrey Harris
+1  A: 

You do need to say it's an NSXMLParserDelegate in SDK4.0. But when I add to the interface definition, it no longer compiles under 3.0, just 4.0.

Under 3.0 it says that it cannot find the protocol def for NSXMLParserDelegate. I've included:

#import <Foundation/NSXMLParser.h>
stoutyhk
A: 

I just downloaded the code from http://cocoadevblog.com/iphone-tutorial-creating-a-rss-feed-reader to see how to implement rss feeder And it shows a warning " class 'Parser' does not implement the 'NSXMLParserDelegate' protocol " at [rssParser setDelegate:self]; in parer.m. App loads in simulator but does not work. I checked in refernces foundation is included. Any idea ?

itska
Hi, post this as a new question not as an answer to this one (top right corner) thats going to be your best way of getting an answer.
fuzzygoat
ok. I'll post it as a new question.
itska
+1  A: 

Although NSXMLParser was introduced from iOS2, The delegate hasn't been introduced until iOS4. Just remove the protocol declaration from your class, that worked for me when compiling against 3.2.

http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/NSXMLParserDelegate_Protocol/Reference/Reference.html

malloc